-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator_test.rb
113 lines (99 loc) · 3.2 KB
/
simulator_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
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
106
107
108
109
110
111
112
113
require 'minitest/autorun'
require_relative 'simulator'
# Class that tests simulator class
class SimulatorTest < Minitest::Test
# UNIT TESTS FOR METHOD run_simulation(prospector_count,pete) in Simulator Class
# Equivalence classes:
# prospector_count = -INFINITY..-1 -> returns nil
# prospector_count = 1..INFINITY -> returns 1, snd tuns simulation as expected
# going to 5 locations
# prospector_count = (not a number) -> returns nil
# prospector_count = 0 -> returns nil
# pete = Object of type Prospector -> returns 1
# pete = Object not of type Prospector -> returns nil
# Test that negative value for prospector_count returns nil
# EDGE CASE
def test_run_simulation_negative
sim = Simulator.new(1, 2)
sim.set_map
mock_prospector = Minitest::Mock.new('Mock Prospector')
def mock_prospector.mine(_param, _param2)
1
end
def mock_prospector.next_location(_param, _param2)
1
end
def mock_prospector.location_count
1
end
assert_nil sim.run_simulation(-1, mock_prospector)
end
# Test that string value for prospector_count returns nil
def test_run_simulation_string
sim = Simulator.new(1, 2)
sim.set_map
mock_prospector = Minitest::Mock.new('Mock Prospector')
def mock_prospector.mine(_param, _param2)
1
end
def mock_prospector.next_location(_param, _param2, _param3)
1
end
def mock_prospector.location_count
1
end
assert_nil sim.run_simulation('HI', mock_prospector)
end
# Test that a value of zero for prospector_count returns nil
# EDGE CASE
def test_run_simulation_zero
sim = Simulator.new(1, 2)
sim.set_map
mock_prospector = Minitest::Mock.new('Mock Prospector')
def mock_prospector.mine(_param, _param2)
1
end
def mock_prospector.next_location(_param, _param2, _param3)
1
end
def mock_prospector.location_count
1
end
assert_nil sim.run_simulation(0, mock_prospector)
end
# Tests that non-negative int value for prospector_count returns a 5. Then
# continues normal behavior and runs the simulation as expected.
# The 5 represents a successful reach of 5 locations
def test_run_simulation_passes
sim = Simulator.new(1, 2)
sim.set_map
mock_prospector = Minitest::Mock.new('Mock Prospector')
def mock_prospector.mine(_param, _param2)
1
end
def mock_prospector.next_location(_param, _param2)
1
end
def mock_prospector.location_count
1
end
assert_equal 5, sim.run_simulation(4, mock_prospector)
end
# UNIT TESTS FOR METHOD set_map() in Simulator Class
# Equivalence classes:
# Accepts no parameters, but it is expected to ALWAYS, return the 2D
# Array displayed below.
def test_set_map
map = [
['Sutter Creek', 'Coloma', 'Angels Camp'],
['Coloma', 'Virginia City', 'Sutter Creek'],
['Angels Camp', 'Nevada City', 'Virginia City', 'Sutter Creek'],
['Nevada City', 'Angels Camp'],
['Virginia City', 'Angels Camp', 'Coloma', 'Midas', 'El Dorado Canyon'],
['Midas', 'Virginia City', 'El Dorado Canyon'],
['El Dorado Canyon', 'Virginia City', 'Midas']
]
sim = Simulator.new(1, 2)
assert_equal map, sim.set_map
end
end