-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rb
More file actions
162 lines (109 loc) · 3.42 KB
/
test.rb
File metadata and controls
162 lines (109 loc) · 3.42 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
load "numgen.rb"
load "writer.rb"
load "html_generator.rb"
class Tests
def initialize(id,dif_mode)
@compiler = C_writer.new(id)
@generator = Generator.new(dif_mode)
end
def tests_generator
type1 #1
type1 #2
type2 #3
type2 #4
type2 #5
type3 #6
type4 #7
type5 #8
type6 #9
type7 #10
type5 #11
type5 #12
clean
end
def type1
orig = @generator.generate_random_hex
shift = rand(6...8)
insert = @generator.generate_random_hex
a = "orig | (insert << #{shift})"
input = "int orig = 0x#{orig};\nint insert = 0x#{insert};\nint a = #{a};\nprintf(\"%x\\n\", a);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def type2
orig = @generator.generate_random_hex
shift = rand(6...8)
insert = @generator.generate_random_hex
a = "orig | (insert << #{shift})"
b = "orig | (insert << #{shift})"
andd = "a & b"
input = "int orig = 0x#{orig};\nint insert = 0x#{insert};\nint a = #{a};\nint b = #{b};\nint andd = #{andd};\nprintf(\"%x\\n\", andd);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def type3
i = @generator.generate_random_hex
number = rand(5..10)
left = "i | (1<<#{number})"
input = "int i = 0x#{i};\nint left = #{left};\nprintf(\"%x\\n\", left);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def type4
value1 = @generator.generate_random_hex_long
shift1 = rand(2..3)
shift2 = rand(2..3)
value2 = @generator.generate_random_hex_long
result = "(value1 << #{shift1}) ^ (value2 >> #{shift2})"
input = "long value1 = 0x#{value1};\nlong value2 = 0x#{value2};\nlong result = #{result};\nprintf(\"%x\\n\", result);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def type5
value1 = rand(100..600)
value2 = rand(100..600)
shift1 = rand(2..3)
shift2 = rand(2..3)
result = "(value1 << #{shift1}) ^ (value2 >> #{shift2})"
input = "int value1 = #{value1};\nint value2 = #{value2};\nint result = #{result};\nprintf(\"%d\\n\", result);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def type6
testValue = @generator.generate_random_hex_long
shift = rand(2..4)
shift = rand(2..4)
if_test = "if(testValue & (1 << #{shift}))"
input = "long testValue = 0x#{testValue};\nint a = 0;\n#{if_test}{a = 1;}\nelse{a = 2;}\nprintf(\"%d\\n\", a);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def type7
testValue = @generator.generate_random_hex_long
shift = rand(2..4)
if_test = "if((result = testValue & testValue ^ testValue | (1 << #{shift})))"
input = "long testValue = 0x#{testValue};\nint a = 0;\nint result = 0;\n#{if_test}{a = 1;}\nelse{a = 2;}\nprintf(\"%d\\n\", a);"
@compiler.set_code(input)
@compiler.lock_n_load
end
def clean
system("rm test.c a.out")
@compiler.html_generate
end
end
tests_to_do = ARGV[0]
tests_difficulty = ARGV[1]
`rm -rf tests`
`mkdir tests`
if tests_to_do == nil
tests_to_do = 1
end
if tests_difficulty == "hard"
tests_difficulty = 1
else
tests_difficulty = 0
end
tests_to_do.to_i.times do |current|
going_test = Tests.new(current+1, tests_difficulty)
going_test.tests_generator
end