You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `assert_eq` function will fail the test if the arguments aren't equal. There are similar functions like `assert()` which just checks if its argument is true, or `assert_ne()` which asserts the two are not equal. Tests are run in parallel, because there's no way for two tests to interfere with each other.
438
438
439
439
Test functions cannot take parameters, nor can they return values. So, what if you want to test many different (expected, actual) pairs for your function? Well, you can call `assert_eq` on a list of values. Like this:
440
440
441
441
```kcl
442
442
#[test]
443
-
multiplication_by_zero() =
444
-
let
445
-
n = 100
446
-
inputs = List.range(0, n) // A list of numbers from `0` to `n`.
447
-
expected = List.replicate(0, n) // A list of length `n`, every element is `0`.
448
-
actual = List.map((x) => x * 0, inputs)
449
-
in
450
-
List.map2(assert_eq, actual, expected)
443
+
multiplication_by_zero = () =>
444
+
let
445
+
n = 100
446
+
inputs = List.range(0, n) // A list of numbers from `0` to `n`.
447
+
expected = List.replicate(0, n) // A list of length `n`, every element is `0`.
448
+
actual = List.map((x) => x * 0, inputs)
449
+
in
450
+
List.map2(assert_eq, actual, expected)
451
451
```
452
452
Here, the function `List.map2` is a lot like `List.map` except it has _two_ input lists. Its function argument takes an element from each list, instead of just from one list. So, it takes a function of type `(a, b) => c`, a `List a` and a `List b` and passes them into the function, element by element, creating a `List c`.
0 commit comments