Skip to content

Commit

Permalink
added append_to_file test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dpbm committed Jun 22, 2024
1 parent f91ca74 commit 99c24b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion auto-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ printf "${GREEN}Running: 'manual_tests'${ENDCOLOR}\n"
printf "\n\n"

printf "${GREEN}Running tests${ENDCOLOR}\n"
cd build && rm -rf *.wg && ctest -V
cd build && rm -rf *.wg && rm -rf *.txt && ctest -V
printf "\n\n"
4 changes: 2 additions & 2 deletions helpers/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ namespace Utils {

double random(double start, double end);
int64_t random_int(uint64_t start, uint64_t end);
void append_to_file(string filename, string data);
vector<Matrix*> parse_weigths(string filename);
NN* parse_nn(string filename);

void create_file(string filename, string data);
void append_to_file(string filename, string data);


//tested
void create_file(string filename, string data);
uint8_t* parse_nn_arch(string line);
double distance(int16_t x1, int16_t y1, int16_t x2, int16_t y2);
Matrix* parse_weights_head(string line);
Expand Down
27 changes: 27 additions & 0 deletions tests/utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using Utils::parse_layers_sizes;
using Utils::parse_activations;
using Utils::parse_row;
using Utils::create_file;
using Utils::append_to_file;

namespace {
TEST(ValueTest, ZeroDistanceTest){
Expand Down Expand Up @@ -238,6 +239,7 @@ namespace {
delete result;
}


TEST(ValueTest, CreateFileTest){
string data = "anything!";
string filename = "test.txt";
Expand All @@ -250,5 +252,30 @@ namespace {
string line;
getline(file, line);
ASSERT_EQ(line, data);

file.close();
}

TEST(ValueTest, AppendToFileTest){
string filename = "test2.txt";
string data1 = "test1";
string data2 = "test2";

append_to_file(filename, data1);
append_to_file(filename, "\n");
append_to_file(filename, data2);

ifstream file(filename);
ASSERT_TRUE(file.good());

string line1;
string line2;
getline(file, line1);
file.seekg(data1.size()+1);
getline(file, line2);
ASSERT_EQ(line1, data1);
ASSERT_EQ(line2, data2);

file.close();
}
}

0 comments on commit 99c24b0

Please sign in to comment.