-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
60 lines (53 loc) · 2.28 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require_relative './lib/kernel_extensions'
require_relative './lib/method_extensions'
require_relative './lib/inline_tests'
require_relative './lib/test_helper'
require_relative './lib/inline_test_failure'
tested def integer_division(x, y)
return Infinity if y.zero?
x.to_i / y.to_i
end,
tests do
assert 6 / 3 == 2, 'it works'
end
tested def add x, y
x + y
end,
tests do
assert_greater_than fuzz[0, (1..1_000)], 0, 'adding anything to zero should be greater than zero'
assert_greater_than fuzz[(1..1_000), 0], 0, 'addition should be commutative'
assert_equal fuzz[0, 0], 0, '0 + 0 = 0'
assert_equal fuzz[1, 1], 2, '1 + 1 = 2'
assert_not_equal fuzz[1, 2], 2, '1 + 2 != 2'
end
tested def subtract x, y
x - y
end,
tests do
assert_equal fuzz[555, 0], 555, '555 - 0 = 555'
assert_greater_than fuzz[10_000, (0..9_999)], 0, 'subtracting n from m where n < m should be greater than 0'
assert_equal fuzz[Float::INFINITY, (0..10_000)], Float::INFINITY, 'subtracting anything from infinity should still be infinity'
end
tested def multiply x, y
x * y
end,
tests do
assert_divisible_by fuzz[3, 5], 5, '3 * 5 should be divisible by 5'
assert_divisible_by fuzz[3, 5], 3, '3 * 5 should be divisible by 3'
assert_divisible_by fuzz[(1..10_000), 5], 5, 'multiplying anything by 5 should be divisible by 5'
assert_equal fuzz[(1..10_000), Float::INFINITY], Float::INFINITY, 'multiplying anything by infinity should be infinity'
assert_equal fuzz[0, Float::INFINITY], 0 * Float::INFINITY, 'multiplying 0 by infinity should be NaN'
end
tested def divide x, y
return Float::INFINITY if y.zero?
x.to_f / y
end,
tests do
assert_equal fuzz[0, 3], 0, 'can use fuzz[x, y] to call function shorthand'
assert_equal fuzz.(0, 3), 0, '0 / 3 = 0'
assert_equal fuzz.(6, 3), 2, '6 / 3 = 2'
assert_equal fuzz.(3, 0), Float::INFINITY, 'dividing by zero results in infinity'
assert_equal fuzz[(0..10_000), 0], Float::INFINITY, 'anything / 0 == infinity'
assert_equal fuzz[0, (1..10_000)], 0, '0 / anything == 0'
end
InlineTests.run!