| 1 |
/* |
| 2 |
Copyright 2015 Google Inc. All rights reserved. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
local f(x) = |
| 18 |
if x < 0 then |
| 19 |
'negative' |
| 20 |
else if x == 0 then |
| 21 |
'zero' |
| 22 |
else if x <= 5 then |
| 23 |
'small' |
| 24 |
else if x <= 10 then |
| 25 |
'large' |
| 26 |
else |
| 27 |
'huge'; |
| 28 |
|
| 29 |
std.assertEqual(f(-10), 'negative') && |
| 30 |
std.assertEqual(f(0), 'zero') && |
| 31 |
std.assertEqual(f(3), 'small') && |
| 32 |
std.assertEqual(f(8), 'large') && |
| 33 |
std.assertEqual(f(100), 'huge') && |
| 34 |
std.assertEqual(if 1 > 0 then 1, 1) && |
| 35 |
std.assertEqual(if 1 > 2 then 1, null) && |
| 36 |
|
| 37 |
std.assertEqual(if true then if false then 'f' else 'y', 'y') && |
| 38 |
std.assertEqual(if true then (if false then 'f') else 'y', null) && |
| 39 |
|
| 40 |
std.assertEqual(if true then if true then 'f' + 'y', 'fy') && |
| 41 |
std.assertEqual(if false then (if true then 'f') + 'y', null) && |
| 42 |
std.assertEqual((if false then (if true then 'f')) + 'y', 'nully') && |
| 43 |
|
| 44 |
true |