@@ -157,5 +157,46 @@ describe('tinyLisp', function() {
157
157
expect ( t . interpret ( t . parse ( "(letrec () 42)" ) ) ) . toEqual ( 42 ) ;
158
158
} ) ;
159
159
} ) ;
160
+
161
+ describe ( 'if' , function ( ) {
162
+ it ( 'should choose the right branch' , function ( ) {
163
+ expect ( t . interpret ( t . parse ( "(if 1 42 4711)" ) ) ) . toEqual ( 42 ) ;
164
+ expect ( t . interpret ( t . parse ( "(if 0 42 4711)" ) ) ) . toEqual ( 4711 ) ;
165
+ } ) ;
166
+ } ) ;
167
+
168
+ describe ( 'and' , function ( ) {
169
+ it ( 'should be true when empty' , function ( ) {
170
+ expect ( t . interpret ( t . parse ( "(and)" ) ) ) . toEqual ( true ) ;
171
+ } ) ;
172
+
173
+ it ( 'should be false if any operand is false' , function ( ) {
174
+ expect ( t . interpret ( t . parse ( "(and 1 1 0 1)" ) ) ) . toEqual ( false ) ;
175
+ expect ( t . interpret ( t . parse ( "(and 0 1" ) ) ) . toEqual ( false ) ;
176
+ expect ( t . interpret ( t . parse ( "(and 1 0" ) ) ) . toEqual ( false ) ;
177
+ } ) ;
178
+
179
+ it ( 'should be true if all operands are true' , function ( ) {
180
+ expect ( t . interpret ( t . parse ( "(and 1 1" ) ) ) . toEqual ( true ) ;
181
+ expect ( t . interpret ( t . parse ( "(and 1" ) ) ) . toEqual ( true ) ;
182
+ } ) ;
183
+ } ) ;
184
+
185
+ describe ( 'or' , function ( ) {
186
+ it ( 'should be false when empty' , function ( ) {
187
+ expect ( t . interpret ( t . parse ( "(or)" ) ) ) . toEqual ( false ) ;
188
+ } ) ;
189
+
190
+ it ( 'should be true if any operand is true' , function ( ) {
191
+ expect ( t . interpret ( t . parse ( "(or 1 1 0 1)" ) ) ) . toEqual ( true ) ;
192
+ expect ( t . interpret ( t . parse ( "(or 0 1" ) ) ) . toEqual ( true ) ;
193
+ expect ( t . interpret ( t . parse ( "(or 1 0" ) ) ) . toEqual ( true ) ;
194
+ } ) ;
195
+
196
+ it ( 'should be false if all operands are false' , function ( ) {
197
+ expect ( t . interpret ( t . parse ( "(or 0 0" ) ) ) . toEqual ( false ) ;
198
+ expect ( t . interpret ( t . parse ( "(or 0" ) ) ) . toEqual ( false ) ;
199
+ } ) ;
200
+ } ) ;
160
201
} ) ;
161
202
} ) ;
0 commit comments