Skip to content

Commit a2241cc

Browse files
committed
fix(exercise): 解决 18 题在 gcc 上自动通过的问题
Signed-off-by: YdrMaster <[email protected]>
1 parent 2bbc748 commit a2241cc

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

exercises/18_function_template/main.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ int plus(int a, int b) {
66
return a + b;
77
}
88

9-
// ---- 不要修改以下代码 ----
109
int main(int argc, char **argv) {
11-
ASSERT(plus(1, 2) == 3, "plus two int");
12-
ASSERT(plus(1u, 2u) == 3u, "plus two unsigned int");
13-
ASSERT(plus(1.f, 2.f) == 3.f, "plus two float");
14-
ASSERT(plus(1.0, 2.0) == 3.0, "plus two double");
10+
ASSERT(plus(1, 2) == 3, "Plus two int");
11+
ASSERT(plus(1u, 2u) == 3u, "Plus two unsigned int");
12+
13+
// THINK: 浮点数何时可以判断 ==?何时必须判断差值?
14+
ASSERT(plus(1.25f, 2.5f) == 3.75f, "Plus two float");
15+
ASSERT(plus(1.25, 2.5) == 3.75, "Plus two double");
16+
// TODO: 修改判断条件使测试通过
17+
ASSERT(plus(0.1, 0.2) == 0.3, "How to make this pass?");
18+
1519
return 0;
1620
}

0 commit comments

Comments
 (0)