Add solutions
This commit is contained in:
parent
7417f01d5d
commit
b056b6ad81
96 changed files with 229 additions and 166 deletions
|
|
@ -83,7 +83,7 @@ fn sub(a: f16, b: f16) f16 {
|
|||
// an error that you need
|
||||
// to correct.
|
||||
test "sub" {
|
||||
try testing.expect(sub(10, 5) == 6);
|
||||
try testing.expect(sub(10, 5) == 5);
|
||||
|
||||
try testing.expect(sub(3, 1.5) == 1.5);
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ fn divide(a: f16, b: f16) !f16 {
|
|||
}
|
||||
|
||||
test "divide" {
|
||||
try testing.expect(divide(2, 2) catch unreachable == 1);
|
||||
try testing.expect(try divide(2, 2) == 1);
|
||||
try testing.expect(divide(-1, -1) catch unreachable == 1);
|
||||
try testing.expect(divide(10, 2) catch unreachable == 5);
|
||||
try testing.expect(divide(1, 3) catch unreachable == 0.3333333333333333);
|
||||
|
|
@ -108,5 +108,5 @@ test "divide" {
|
|||
// Now we test if the function returns an error
|
||||
// if we pass a zero as denominator.
|
||||
// But which error needs to be tested?
|
||||
try testing.expectError(error.???, divide(15, 0));
|
||||
try testing.expectError(error.DivisionByZero, divide(15, 0));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue