-
Notifications
You must be signed in to change notification settings - Fork 0
/
stutestNoErrors.in
279 lines (256 loc) · 6.99 KB
/
stutestNoErrors.in
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
; Testing
[let [: string1 string] "hello"]
[let [: string2 string] "joe"]
[let [: easy int] -2]
[let [: peasy int] 3]
[+ easy peasy]
[writestring stdout "[let [: stringTest string] \"Mark Funk\"]
[:= stringTest [+ stringTest \" Testing\n\"]]
[writestring stdout stringTest]"]
[let [: stringTest string] "Mark Funk"]
[:= stringTest [+ stringTest " Testing\n"]]
[writestring stdout stringTest]
[writestring stdout "Testing Associative Assignment"]
[writestring stdout
"[let [: a1 int] 1]
[let [: a2 int] 2]
[let [: a3 int] 3]
[let [: a4 int] 4]
[let [: a5 int] 5]
[:= a1 [:= a2 [:= a3 [:= a4 a5]]]]
[writeint stdout a1]"]
[let [: a1 int] 1]
[let [: a2 int] 2]
[let [: a3 int] 3]
[let [: a4 int] 4]
[let [: a5 int] 5]
[:= a1 [:= a2 [:= a3 [:= a4 a5]]]]
[writeint stdout a1]
[writestring stdout "Testing While Loops"]
[writestring stdout "Print from 1 to 10(and for each number print 1 - 5)"]
[writestring stdout "This tests nested variables to make sure they are reinstanced"]
[let [: whileCount int] 1]
[while [<= whileCount 10]
[
begin
[writeint stdout whileCount]
[let [: whileCount2 int] 1]
[while [<= whileCount2 5]
[
begin
[writeint stdout whileCount2]
[:= whileCount2 [+ whileCount2 1]]
end
]
]
[writestring stdout ""]
[:= whileCount [+ whileCount 1]]
end
]
]
[writestring stdout "\nTo prove number isn't taken, will create int with name whileCount2 and print"]
[let [: whileCount2 int] 1]
[writeint stdout whileCount2]
[writestring stdout "\nFibonacci Number Sequence until Number is greater than 50"]
[let [: oldNumber int] 1]
[let [: currentNumber int] 1]
[let [: nextNumber int] 0]
[while [< currentNumber 50]
[
begin
[writeint stdout currentNumber]
[:= nextNumber [+ currentNumber oldNumber]]
[:= oldNumber currentNumber]
[:= currentNumber nextNumber]
end
]
]
[writestring stdout "\nIf Statement/BeginEnd Testing"]
[writestring stdout "Checks if 1 < 2, if so prints out 10, 11 then adds them together(stored in variables)"]
[writestring stdout "integer1 and integer2 are local to if clause integer3 and integer4 are local to else clause"]
[if [< 1 2]
[
begin
[let [: integer1 int] 10]
[let [: integer2 int] 11]
[writeint stdout integer1]
[writeint stdout integer2]
[writeint stdout [+ integer1 integer2]]
end
]
[
begin
[let [: integer3 int] 100]
[let [: integer4 int] 110]
[writeint stdout integer3]
[writeint stdout integer4]
[writeint stdout [+ integer3 integer4]]
end
]
]
[writestring stdout "\nGlobal Testing and Using Variables in Let"]
[writestring stdout "[let [: x int] [+ 1 2]]"] [let [: x int] [+ 1 2]]
[writestring stdout "[writeint stdout x]"] [writeint stdout x]
[writestring stdout "[:= x 1]"] [:= x 1]
[writestring stdout "[let [: y int] [+ 1 x]]"] [let [: y int] [+ 1 x]]
[writestring stdout "[writeint stdout x]"] [writeint stdout x]
[writestring stdout "[writeint stdout y]"] [writeint stdout y]
; Nested If
[writestring stdout "\nNested If Testing"]
[writestring stdout "The following sets the Global variable Z to be True"]
[writestring stdout "Followed by a 4 argument let of Z(creates new instance) setting it to false"]
[writestring stdout "Flow setting Z to False->True->False(in Begin/End clause)"]
[writestring stdout "Afterwards outside of Let prints Z, gets global value of True\n"]
[writestring stdout "[let [: z bool] true]
[let [: z bool] false
[if [z] ; Should be false
[writestring stdout \"First If True\"]
[let [: z bool] true
[if [z] ; Should be true
[
begin
[writestring stdout \"Else, Second If True\"]
[let [: z bool] false]
end
]
[writestring stdout \"Else, Second If False\"]
]
]
]
]
[writebool stdout z] ; Should be true
"]
[let [: z bool] true]
[let [: z bool] false
[if [z] ; Should be false
[writestring stdout "First If True"]
[let [: z bool] true
[if [z] ; Should be true
[
begin
[writestring stdout "Else, Second If True"]
[let [: z bool] false]
end
]
[writestring stdout "Else, Second If False"]
]
]
]
]
[writebool stdout z] ; Should be true
; Simple Case
[writestring stdout "Simple Case - add function"]
[let [: [add [: x int] [: y int]] int]
[begin
[writestring stdout "Adding two integers together using created function - add"]
[+ x y]
end
]
]
[writeint stdout [add 1 2 ]]
;Block Code Testing
[writestring stdout "\nBlock Code Testing - Function called in block"]
[let [: [secondAdd [: x float] [: y float]] float]
[begin
[writestring stdout "Adding two floats together where function only exists in code block"]
[+ x y]
end
]
[writefloat stdout [secondAdd 3.0 4.0 ]]
]
;Void testing
[writestring stdout "\nVoid Testing"]
[let [: [connectDots] void]
[begin
[writestring stdout "I'm a void function!"]
end
]
]
[connectDots]
;Using Factorial for Recursive Testing
[writestring stdout "\nUsing Factorial for Recursive Testing"]
[writestring stdout "
[let [: [factorial [: number int]] int]
[
begin
[if [<= number 1]
[+ 1 0]
[* number [factorial [- number 1]]]
]
end
]
]"]
[let [: [factorial [: number int]] int]
[
begin
[if [<= number 1]
[+ 1 0]
[* number [factorial [- number 1]]]
]
end
]
]
[writestring stdout "Testing statement \n[writeint stdout [factorial 4]]"]
[writeint stdout [factorial 4]]
[writestring stdout "\nMore Recursive Testing with Fibonacci Numbers"]
[writestring stdout "
[let [: [fibonacci [: n int]] int]
[if [| [= n 1] [= n 2]]
[+ 1 0]
[+ [fibonacci [- n 1]] [fibonacci [- n 2]]]
]
]
"]
[let [: [fibonacci [: n int]] int]
[if [| [= n 1] [= n 2]]
[+ 1 0]
[+ [fibonacci [- n 1]] [fibonacci [- n 2]]]
]
]
[writestring stdout "The 7th Number in the Fibonacci Sequence is "]
[writeint stdout [fibonacci 7]]
;Function assignment
[writestring stdout "\nTesting function assignment\n[let [: [newFactorial [: number int]] int] factorial]"]
[let [: [newFactorial [: number int]] int] factorial]
[writestring stdout "[writeint stdout [newFactorial 5]]"]
[writeint stdout [newFactorial 5]]
[writestring stdout "\nCreate a useless function, assign a function with same signature to it"]
[writestring stdout "[let [: [bizarro [: number int]] int] 7]\n[:= bizarro newFactorial]"]
[let [: [bizarro [: number int]] int] 7]
[:= bizarro newFactorial]
[writestring stdout "Now Call it\n[writeint stdout [bizarro 5]]"]
[writeint stdout [bizarro 5]]
[writestring stdout "\n\nFunctions within Functions, also Pass by Value"]
[writestring stdout "
[let [: [function1 [: x int]] int]
[
begin
[let [: [function2 [: y int]] int]
[
begin
[+ 1 y]
end
]
]
[writeint stdout [function2 x]]
[+ 1 x]
end
]
]
[writeint stdout [function1 9]]"]
[let [: [function1 [: x int]] int]
[
begin
[let [: [function2 [: y int]] int]
[
begin
[+ 1 y]
end
]
]
[writeint stdout [function2 x]]
[+ 1 x]
end
]
]
[writeint stdout [function1 9]]