feat(01): Solved part 1
This commit is contained in:
parent
baf227ce23
commit
118f3632a9
8 changed files with 3957 additions and 36 deletions
01/tests/src
|
@ -1,31 +1,50 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#define TESTING
|
||||
|
||||
// Include the source file(s) to be tested.
|
||||
#include "main.c"
|
||||
|
||||
// Create a test fixture class template - this will be like a "conlection" of
|
||||
// tests. the : public ::testing::Test part is important! Add it to your fixture
|
||||
// class.
|
||||
class HelloTest : public ::testing::Test {
|
||||
HelloTest() {}
|
||||
void stream_add(FILE *stream, std::string string) {
|
||||
fprintf(stream, "%s", string.c_str());
|
||||
fseek(stream, -string.length(), SEEK_CUR);
|
||||
}
|
||||
|
||||
~HelloTest() {}
|
||||
class Trebuchet : public ::testing::Test {
|
||||
public:
|
||||
FILE *input;
|
||||
|
||||
void SetUp() {}
|
||||
Trebuchet() {}
|
||||
|
||||
~Trebuchet() {}
|
||||
|
||||
void SetUp() {
|
||||
input = tmpfile();
|
||||
if (input == NULL) {
|
||||
fprintf(stderr, "Error creating tmpfile\n");
|
||||
fprintf(stderr, "Error: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
// Add tests to the test fixture class.
|
||||
// @param fixture_class_name The name of the test fixture class.
|
||||
// @param test_name The name of the test.
|
||||
TEST(HelloTest, BasicAssertions) {
|
||||
// Execute the code to be tested.
|
||||
// Expect two strings not to be equal.
|
||||
EXPECT_STRNE("hello", "world");
|
||||
// Expect equality.
|
||||
EXPECT_EQ(7 * 6, 42);
|
||||
TEST_F(Trebuchet, AssignmentInput) {
|
||||
testing::internal::CaptureStdout();
|
||||
stream_add(input, "1abc2\npqr3stu8vwx\na1b2c3d4e5f\ntreb7uchet");
|
||||
char* argv[2];
|
||||
mainTest(input, 1, argv);
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
// Check the output of the program.
|
||||
EXPECT_EQ("The sum of the calibration values is 142\n", output);
|
||||
}
|
||||
|
||||
TEST_F(Trebuchet, getVal) {
|
||||
EXPECT_EQ(12, getVal((char *)"1abc2"));
|
||||
EXPECT_EQ(38, getVal((char *)"pqr3stu8vwx"));
|
||||
EXPECT_EQ(15, getVal((char *)"a1b2c3d4e5f"));
|
||||
EXPECT_EQ(77, getVal((char *)"treb7uchet"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue