Skip to content

Commit

Permalink
Add exercise 1-6
Browse files Browse the repository at this point in the history
  • Loading branch information
winswu committed Nov 24, 2024
1 parent 68b724f commit 816067d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chapter_1/exercise_1_6/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cc_test(
name = "test",
size = "small",
srcs = ["test/test.cc"],
deps = [
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
23 changes: 23 additions & 0 deletions chapter_1/exercise_1_6/test/test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <gtest/gtest.h>
#include <limits.h>
#include <stdio.h>

TEST(Exercise_1_6, VerifyEof) {
int expression_result = 0;

FILE *fp = fopen("input.txt", "w");

for (int i = 0; i < SCHAR_MAX; i++) {
fputc(i, fp);
}

fclose(fp);

freopen("input.txt", "r", stdin);

while ((expression_result = getchar() != EOF)) {
EXPECT_EQ(1, expression_result);
}

EXPECT_EQ(0, expression_result);
}

0 comments on commit 816067d

Please sign in to comment.