Skip to content

Commit

Permalink
fix(exercise): 解决 18 题在 gcc 上自动通过的问题
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <[email protected]>
  • Loading branch information
YdrMaster committed Jul 15, 2024
1 parent 2bbc748 commit a2241cc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions exercises/18_function_template/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ int plus(int a, int b) {
return a + b;
}

// ---- 不要修改以下代码 ----
int main(int argc, char **argv) {
ASSERT(plus(1, 2) == 3, "plus two int");
ASSERT(plus(1u, 2u) == 3u, "plus two unsigned int");
ASSERT(plus(1.f, 2.f) == 3.f, "plus two float");
ASSERT(plus(1.0, 2.0) == 3.0, "plus two double");
ASSERT(plus(1, 2) == 3, "Plus two int");
ASSERT(plus(1u, 2u) == 3u, "Plus two unsigned int");

// THINK: 浮点数何时可以判断 ==?何时必须判断差值?
ASSERT(plus(1.25f, 2.5f) == 3.75f, "Plus two float");
ASSERT(plus(1.25, 2.5) == 3.75, "Plus two double");
// TODO: 修改判断条件使测试通过
ASSERT(plus(0.1, 0.2) == 0.3, "How to make this pass?");

return 0;
}

0 comments on commit a2241cc

Please sign in to comment.