mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
refactor(test): remove tests (for now)
This commit is contained in:
parent
6ed14fd2c0
commit
29f9e60a33
@ -1,7 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.1...3.28)
|
cmake_minimum_required(VERSION 3.1...3.28)
|
||||||
|
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
project(
|
project(
|
||||||
Template
|
Template
|
||||||
VERSION 0.1.0
|
VERSION 0.1.0
|
||||||
@ -9,28 +7,11 @@ project(
|
|||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
add_subdirectory(src/cppunit)
|
|
||||||
add_subdirectory(src/modules)
|
add_subdirectory(src/modules)
|
||||||
|
|
||||||
add_executable(main src/main.cc)
|
add_executable(main src/main.cc)
|
||||||
add_library(lib src/lib.cc src/lib.hh src/validation.cc src/validation.hh)
|
add_library(validation src/validation.cc src/validation.hh)
|
||||||
target_link_libraries(main PUBLIC lib)
|
target_link_libraries(main PUBLIC validation)
|
||||||
target_link_libraries(lib PUBLIC modules)
|
target_link_libraries(validation PUBLIC modules)
|
||||||
target_include_directories(main PUBLIC "${PROJECT_BINARY_DIR}"
|
target_include_directories(main PUBLIC "${PROJECT_BINARY_DIR}"
|
||||||
"${PROJECT_SOURCE_DIR}/prep")
|
"${PROJECT_SOURCE_DIR}/modules")
|
||||||
target_include_directories(lib PUBLIC "${PROJECT_BINARY_DIR}"
|
|
||||||
"${PROJECT_SOURCE_DIR}/prep")
|
|
||||||
|
|
||||||
include(FetchContent)
|
|
||||||
FetchContent_Declare(
|
|
||||||
googletest
|
|
||||||
URL https://github.com/google/googletest/archive/5376968f6948923e2411081fd9372e71a59d8e77.zip
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(googletest)
|
|
||||||
|
|
||||||
add_executable(runtests src/test.cc)
|
|
||||||
target_link_libraries(runtests PUBLIC lib gtest gtest_main)
|
|
||||||
target_include_directories(runtests PUBLIC "${PROJECT_BINARY_DIR}")
|
|
||||||
|
|
||||||
include(GoogleTest)
|
|
||||||
gtest_discover_tests(runtests)
|
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
add_library(cppunit cppunit.cc cppunit.hh)
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
|
|
||||||
#ifndef CPPUNIT_H
|
|
||||||
#define CPPUNIT_H
|
|
||||||
|
|
||||||
// Required headers, or just use #include <bits/stdc++.h>
|
|
||||||
#include <cstring>
|
|
||||||
#include <ctime>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
// CPlusPlusUnit - C++ Unit testing TDD framework (github.com/cppunit/cppunit)
|
|
||||||
class Cppunit {
|
|
||||||
public:
|
|
||||||
#define CHECK(a, b) check<long long>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
|
||||||
#define CHECKT(a) check<bool>(a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
|
|
||||||
#define CHECKS(a, b) check<cs>(a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
|
|
||||||
typedef const std::string &cs;
|
|
||||||
int checks, fails;
|
|
||||||
std::ostringstream serr;
|
|
||||||
std::istringstream *in;
|
|
||||||
|
|
||||||
Cppunit() {
|
|
||||||
checks = fails = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_cin(cs s) {
|
|
||||||
in = new std::istringstream(s);
|
|
||||||
std::cin.rdbuf(in->rdbuf());
|
|
||||||
}
|
|
||||||
|
|
||||||
void fail_hdr(cs stra, cs strb, cs file, int line, cs func) {
|
|
||||||
serr << "==================================================" << std::endl;
|
|
||||||
serr << "FAIL: " << func << std::endl;
|
|
||||||
serr << "--------------------------------------------------" << std::endl;
|
|
||||||
serr << "File \"" << file << "\", line " << line << " in " << func << std::endl;
|
|
||||||
serr << " Checking " << stra << " == " << strb << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T> void check(T a, T b, cs stra, cs strb, cs file, int line, cs func) {
|
|
||||||
checks++;
|
|
||||||
if (a == b) {
|
|
||||||
std::cout << ".";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fails++;
|
|
||||||
std::cout << "F";
|
|
||||||
fail_hdr(stra, strb, file, line, func);
|
|
||||||
serr << " Error: \"" << a << "\" ! = \"" << b << "\"" << std::endl << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void single_test() {
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void test_list() {
|
|
||||||
single_test();
|
|
||||||
}
|
|
||||||
|
|
||||||
double dclock() {
|
|
||||||
return double(clock()) / CLOCKS_PER_SEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
int status() {
|
|
||||||
std::cout << std::endl;
|
|
||||||
if (fails) std::cout << serr.str();
|
|
||||||
std::cout << "--------------------------------------------------" << std::endl;
|
|
||||||
std::cout << "Ran " << checks << " checks in " << dclock() << "s" << std::endl << std::endl;
|
|
||||||
if (fails)
|
|
||||||
std::cout << "FAILED (failures=" << fails << ")";
|
|
||||||
else
|
|
||||||
std::cout << "OK" << std::endl;
|
|
||||||
return fails > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int run() {
|
|
||||||
std::streambuf *ocin = std::cin.rdbuf();
|
|
||||||
test_list();
|
|
||||||
std::cin.rdbuf(ocin);
|
|
||||||
return status();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CPPUNIT_H
|
|
||||||
@ -1 +0,0 @@
|
|||||||
#include "./validation.hh"
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "./lib.hh"
|
#include "./validation.hh"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
|
|||||||
Player player2 = Player(420, "player2", role1, player::Alive);
|
Player player2 = Player(420, "player2", role1, player::Alive);
|
||||||
Room room1(1, "Room 1", 1710087364, room::InProgress, {player1, player2});
|
Room room1(1, "Room 1", 1710087364, room::InProgress, {player1, player2});
|
||||||
Room room2(2, "Room 2", 1710087384, room::Ended, {});
|
Room room2(2, "Room 2", 1710087384, room::Ended, {});
|
||||||
int actionValidated = validateAction(&player1, &kill, &room1, &relatedEvents, &player2);
|
int validated_action = validate_action(&player1, &kill, &room1, &relatedEvents, &player2);
|
||||||
printf("The action validation result is %u\n", actionValidated);
|
printf("The action validation result is %u\n", validated_action);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,16 +10,16 @@
|
|||||||
Room::Room(uint32_t id, std::string title, uint32_t created_at, room::Status status, std::vector<Player> players):
|
Room::Room(uint32_t id, std::string title, uint32_t created_at, room::Status status, std::vector<Player> players):
|
||||||
id(id),
|
id(id),
|
||||||
title(title),
|
title(title),
|
||||||
created_at(create_utc_timestamp(created_at)),
|
|
||||||
status(status),
|
status(status),
|
||||||
players(players) {
|
players(players) {
|
||||||
|
this->created_at = create_utc_timestamp(created_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
Room::Room(
|
Room::Room(
|
||||||
uint32_t id, std::string title, uint32_t created_at, room::Status status, std::initializer_list<Player> players):
|
uint32_t id, std::string title, uint32_t created_at, room::Status status, std::initializer_list<Player> players):
|
||||||
id(id),
|
id(id),
|
||||||
title(title),
|
title(title),
|
||||||
created_at(create_utc_timestamp(created_at)),
|
|
||||||
status(status),
|
status(status),
|
||||||
players(players) {
|
players(players) {
|
||||||
|
this->created_at = create_utc_timestamp(created_at);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
|
#include "./time.hh"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
std::tm *create_utc_imestamp(uint32_t timestamp) {
|
std::tm *create_utc_timestamp(uint32_t timestamp) {
|
||||||
// Convert the timestamp into a time_point object
|
// Convert the timestamp into a time_point object
|
||||||
std::chrono::seconds sec(timestamp);
|
std::chrono::seconds sec(timestamp);
|
||||||
std::chrono::time_point<std::chrono::system_clock> tp(sec);
|
std::chrono::time_point<std::chrono::system_clock> tp(sec);
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
TEST(ProgramTest, testFunction) {
|
|
||||||
EXPECT_EQ(8, 8);
|
|
||||||
}
|
|
||||||
@ -27,7 +27,7 @@ bool is_action_allowed(const Action *action, std::vector<Event> *relevantEvents)
|
|||||||
return allowed;
|
return allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int validateAction(
|
int validate_action(
|
||||||
Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
|
Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target = nullptr) {
|
||||||
if (!actor) {
|
if (!actor) {
|
||||||
return validation::NoActor;
|
return validation::NoActor;
|
||||||
|
|||||||
@ -23,6 +23,6 @@ namespace validation {
|
|||||||
};
|
};
|
||||||
} // namespace validation
|
} // namespace validation
|
||||||
|
|
||||||
int validateAction(Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target);
|
int validate_action(Player *actor, const Action *action, Room *room, std::vector<Event> *relatedEvents, Player *target);
|
||||||
|
|
||||||
#endif // !VALIDATION_HH
|
#endif // !VALIDATION_HH
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user