forked from rails-decal/sp18-hw1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autograder.rb
executable file
·62 lines (54 loc) · 1.79 KB
/
autograder.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
require './hw1'
def check_squared_sum
first_sum = squared_sum 1, 2
second_sum = squared_sum 2, 5
raise "Squared sum expected to return 9 with inputs 1 and 2, got #{ first_sum }" unless first_sum == 9
raise "Squared sum expected to return 9 with inputs 2 and 5, got #{ second_sum }" unless second_sum == 49
puts 'Q1 Success!'
end
def check_sort_array
arr = [18, 27, 100, -5, 6, 7]
expected_output_arr = [-4, 7, 8, 19, 28, 101]
output_arr = sort_array_plus_one arr
error_str = %(
Array is not sorted or summed properly.
Input was #{arr}.
Expected output was #{expected_output_arr}.
Got #{output_arr}."
)
raise error_str unless output_arr == expected_output_arr
puts 'Q2 Success!'
end
def check_combine_name
output_name = combine_name 'Chuck', 'Norris'
raise "Expected Chuck Norris, got #{output_name}" unless output_name == "Chuck Norris"
'Q3 Success'
puts 'Q3 Success!'
end
def check_blockin_time
input = ["1", "2", "3", "4", "5", "10"]
first_output = blockin_time input
second_output = blockin_time input
raise "Expected baz to compute 10, got #{first_output} for input #{ input }." unless first_output == 10
raise "Expected baz to compute 10, got #{second_output} for input #{ input }." unless first_output == 10
puts 'Q4 Success!'
end
def check_scrabble
input = ["scream", "ruby", "on", "rails", "decal", "quixotry", "oxyphenbutazone"]
expected_output = [10, 9, 2, 5, 8, 27, 41]
output = input.map { |w| scrabble w }
error_str = %(
Scrabble was not computed correctly.
Input was #{input}.
Expected output was #{expected_output}.
Got #{output}."
)
raise error_str unless output == expected_output
puts 'Q5 Success!'
end
check_squared_sum
check_sort_array
check_combine_name
check_blockin_time
check_scrabble
puts 'All functions work!'