summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Boesch <chrboesch@noreply.codeberg.org>2025-10-25 00:02:26 +0200
committerChris Boesch <chrboesch@noreply.codeberg.org>2025-10-25 00:02:26 +0200
commit7ad02b084fa129e4f920e8b66072ba55524740eb (patch)
tree0a2fcc119bd194548cf76d0662ae7270370eaa61
parentb72bcd7e476f88f8ade4cd46586bac17181f929b (diff)
parenta5622fd5a84a6acfce9ec25c84f1e3b21afbb286 (diff)
Merge pull request 'Wrap comment at 80 chars in 102' (#314) from whlr/ziglings-exercises:rewrap-102 into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/314
-rw-r--r--exercises/102_testing.zig50
-rw-r--r--patches/patches/102_testing.patch18
2 files changed, 26 insertions, 42 deletions
diff --git a/exercises/102_testing.zig b/exercises/102_testing.zig
index 248f5b5..0dec9b9 100644
--- a/exercises/102_testing.zig
+++ b/exercises/102_testing.zig
@@ -37,63 +37,48 @@
const std = @import("std");
const testing = std.testing;
-// This is a simple function
-// that builds a sum from the
-// passed parameters and returns.
+// This is a simple function that builds a sum from the passed parameters and
+// returns.
fn add(a: f16, b: f16) f16 {
return a + b;
}
-// The associated test.
-// It always starts with the keyword "test",
-// followed by a description of the tasks
-// of the test. This is followed by the
-// test cases in curly brackets.
+// The associated test. It always starts with the keyword "test", followed by a
+// description of the tasks of the test. This is followed by the test cases in
+// curly brackets.
test "add" {
- // The first test checks if the sum
- // of '41' and '1' gives '42', which
- // is correct.
+ // The first test checks if the sum of '41' and '1' gives '42', which is
+ // correct.
try testing.expect(add(41, 1) == 42);
- // Another way to perform this test
- // is as follows:
+ // Another way to perform this test is as follows:
try testing.expectEqual(42, add(41, 1));
- // This time a test with the addition
- // of a negative number:
+ // This time a test with the addition of a negative number:
try testing.expect(add(5, -4) == 1);
// And a floating point operation:
try testing.expect(add(1.5, 1.5) == 3);
}
-// Another simple function
-// that returns the result
-// of subtracting the two
+// Another simple function that returns the result of subtracting the two
// parameters.
fn sub(a: f16, b: f16) f16 {
return a - b;
}
-// The corresponding test
-// is not much different
-// from the previous one.
-// Except that it contains
-// an error that you need
-// to correct.
+// The corresponding test is not much different from the previous one. Except
+// that it contains an error that you need to correct.
test "sub" {
try testing.expect(sub(10, 5) == 6);
try testing.expect(sub(3, 1.5) == 1.5);
}
-// This function divides the
-// numerator by the denominator.
-// Here it is important that the
-// denominator must not be zero.
-// This is checked and if it
-// occurs an error is returned.
+// This function divides the numerator by the denominator. Here it is important
+// that the denominator must not be zero. This is checked and if it occurs an
+// error is returned.
fn divide(a: f16, b: f16) !f16 {
if (b == 0) return error.DivisionByZero;
return a / b;
@@ -105,8 +90,7 @@ test "divide" {
try testing.expect(divide(10, 2) catch unreachable == 5);
try testing.expect(divide(1, 3) catch unreachable == 0.3333333333333333);
- // Now we test if the function returns an error
- // if we pass a zero as denominator.
- // But which error needs to be tested?
+ // 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));
}
diff --git a/patches/patches/102_testing.patch b/patches/patches/102_testing.patch
index 9695b24..6d18bf6 100644
--- a/patches/patches/102_testing.patch
+++ b/patches/patches/102_testing.patch
@@ -1,18 +1,18 @@
---- exercises/102_testing.zig 2023-10-03 22:15:22.125574535 +0200
-+++ answers/102_testing.zig 2023-10-05 20:04:07.302771500 +0200
-@@ -83,7 +83,7 @@
- // an error that you need
- // to correct.
+--- exercises/102_testing.zig 2025-10-24 12:54:56
++++ answers/102_testing.zig 2025-10-24 12:56:33
+@@ -71,7 +71,7 @@
+ // The corresponding test is not much different from the previous one. Except
+ // that it contains 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);
}
-@@ -108,5 +108,5 @@
- // Now we test if the function returns an error
- // if we pass a zero as denominator.
- // But which error needs to be tested?
+@@ -92,5 +92,5 @@
+
+ // 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));
}