-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.lua
106 lines (87 loc) · 2.6 KB
/
test.lua
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
require('test/lunit');
require('calculator');
module("test",lunit.testcase,package.seeall);
function setup()
string="Hi there"
boolean=true
end
function test_add()
result=calculator.calculate(1,3,calculator.add);
assert_equal('number',type(result));
assert_equal(4,result);
end
function test_add_non_number()
if pcall(calculator.calculate,1,string,calculator.add) then
fail("Add did not fail on incorrect input!");
end
end
function test_add_negative()
result=calculator.calculate(1,-3,calculator.add);
assert_equal('number',type(result));
assert_equal(2,result);
end
function test_add_real()
result=calculator.calculate(1,3.5,calculator.add);
assert_equal('number',type(result));
assert_equal(4.5,result);
end
function test_subtract()
result=calculator.calculate(1,3,calculator.subtract);
assert_equal('number',type(result));
assert_equal(-2,result);
end
function test_subtract_negative()
result=calculator.calculate(1,-3,calculator.subtract);
assert_equal('number',type(result));
assert_equal(4,result);
end
function test_subtract_real()
result=calculator.calculate(1,3.5,calculator.subtract);
assert_equal('number',type(result));
assert_equal(-2.5,result);
end
function test_subtract_non_number()
if pcall(calculator.calculate,1,string,calculator.subtract) then
fail("Subtract did not fail on incorrect input!");
end
end
function test_multiply()
result=calculator.calculate(2,3,calculator.multiply);
assert_equal('number',type(result));
assert_equal(6,result);
end
function test_multiply_negative()
result=calculator.calculate(2,-3,calculator.multiply);
assert_equal('number',type(result));
assert_equal(-6,result);
end
function test_multiply_real()
result=calculator.calculate(2,3.5,calculator.multiply);
assert_equal('number',type(result));
assert_equal(7,result);
end
function test_multiply_non_number()
if pcall(calculator.calculate,1,string,calculator.multiply) then
fail("Multiply did not fail on incorrect input!");
end
end
function test_divide()
result=calculator.calculate(100,2,calculator.divide);
assert_equal('number',type(result));
assert_equal(50,result);
end
function test_divide_non_number()
if pcall(calculator.calculate,1,string,calculator.divide) then
fail("Divide did not fail on incorrect input!");
end
end
function test_modulus()
result=calculator.calculate(100,11,calculator.modulus);
assert_equal('number',type(result));
assert_equal(1,result);
end
function test_modulus_non_number()
if pcall(calculator.calculate,1,string,calculator.modulus) then
fail("Modulus did not fail on incorrect input!");
end
end