-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstutest.in
executable file
·163 lines (150 loc) · 4.09 KB
/
stutest.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
; Testing
; 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]]
;Error Cases
[writestring stdout "\n\nError Cases : No Output Given for These, Check Compiler Error Messages"]
[writestring stdout "\nNested Function function2 does not exist outside of function1\n[function2 9]"]
[writeint stdout [function2 9]]
[writestring stdout "\nFunction return type does not match signature for return type
[let [: [connectDotsAgain] void]
[begin
[writestring stdout \"Connect the Dots, la la la\"]
[+ 1 2]
end
]
]"]
[let [: [connectDotsAgain] void]
[begin
[writestring stdout "Connect the Dots, la la la"]
[+ 1 2]
end
]
]
[writestring stdout "\nNotice secondAdd can't be called now, because it only existed in block of code"]
[writestring stdout "[writeint stdout [secondAdd 1 2 ]]"]
[writeint stdout [secondAdd 1 2 ]]
[writestring stdout "\nIncorrect Number of Arguments\n[add 1 2 3]"]
[add 1 2 3]
[writestring stdout "Wrong Type of Arguments\n[add 1.0 2]"]
[add 1.0 2]
; Functions are recognized as distinct from variables even though they use similar protocol
[writestring stdout "\nFunctions are recognized as distinct from variables\nEven though they use a similar protocol"]
[writestring stdout "[+ add 2]"]
[+ add 2]
[writestring stdout "\nFunctions with different signatures cannot be assigned to one another"]
[writestring stdout "[:= add bizarro]"]
[:= add bizarro]