-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cc_library( | ||
name = "lib", | ||
srcs = ["lib.c"], | ||
hdrs = ["lib.h"], | ||
) | ||
|
||
cc_test( | ||
name = "test", | ||
size = "small", | ||
srcs = ["test/test.cc"], | ||
deps = [ | ||
":lib", | ||
"@googletest//:gtest", | ||
"@googletest//:gtest_main", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
|
||
/* print Fahrenheit-Celsius table */ | ||
int exercise_1_5() | ||
{ | ||
int fahr; | ||
|
||
for (fahr = 300; fahr >= 0; fahr = fahr - 20) | ||
printf("%3d %6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
int exercise_1_5(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
extern "C" { | ||
#include "../lib.h" | ||
} | ||
|
||
TEST(Exercise_1_5, ReverseOrder) { | ||
std::string line; | ||
|
||
testing::internal::CaptureStdout(); | ||
|
||
exercise_1_5(); | ||
|
||
std::string output = testing::internal::GetCapturedStdout(); | ||
|
||
EXPECT_EQ(output, | ||
"300 148.9\n" | ||
"280 137.8\n" | ||
"260 126.7\n" | ||
"240 115.6\n" | ||
"220 104.4\n" | ||
"200 93.3\n" | ||
"180 82.2\n" | ||
"160 71.1\n" | ||
"140 60.0\n" | ||
"120 48.9\n" | ||
"100 37.8\n" | ||
" 80 26.7\n" | ||
" 60 15.6\n" | ||
" 40 4.4\n" | ||
" 20 -6.7\n" | ||
" 0 -17.8\n"); | ||
} |