Number
Check if a value is a number
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
value | output |
---|---|
#f | B |
’() | B |
0 | A |
42 | A |
-2045 | A |
Check a number trait
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
predicate | value | output |
---|---|---|
zero? | 0 | A |
zero? | 1 | B |
positive? | 42 | A |
positive? | -42 | B |
negative? | -42 | A |
negative? | 42 | B |
even? | 2 | A |
even? | 3 | B |
odd? | 3 | A |
odd? | 2 | B |
Check a number class of integers
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
predicate | value | output |
---|---|---|
number? | 0 | A |
number? | 1 | A |
number? | -42 | A |
complex? | 0 | A |
complex? | 1 | A |
complex? | -42 | A |
real? | 0 | A |
real? | 1 | A |
real? | -42 | A |
rational? | 0 | A |
rational? | 1 | A |
rational? | -42 | A |
integer? | 0 | A |
integer? | 1 | A |
integer? | -42 | A |
Check a number class of floating point numbers
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
predicate | value | output |
---|---|---|
number? | 3.14 | A |
number? | -42.2045 | A |
complex? | 3.14 | A |
complex? | -42.2045 | A |
real? | 3.14 | A |
real? | -42.2045 | A |
rational? | 0 | A |
rational? | 1 | A |
rational? | -42 | A |
rational? | 3.14 | A |
rational? | -42.2045 | A |
rational? | (exp 1) | A |
integer? | 3.14 | B |
integer? | -42.2045 | B |
Check a number class of non-numbers
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “B”.
Examples
predicate |
---|
number? |
complex? |
real? |
rational? |
integer? |
Use literals
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the exit status should be 0.
Examples
value |
---|
0 |
1 |
42 |
-1 |
-42 |
Use a negative integer
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Use large (but not big) integers
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Use integers around the encoding base
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
value | output |
---|---|
127 | C |
128 | D |
129 | E |
Use arithmetic operators
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
expression | value |
---|---|
(+) | 0 |
(+ 1) | 1 |
(+ 1 2) | 3 |
(- 1) | -1 |
(- 0 1) | -1 |
(- 0 1 2) | -3 |
(*) | 1 |
(* 2) | 2 |
(* 2 3) | 6 |
(/ 6 2) | 3 |
(/ 6 2 3) | 1 |
Use division operators
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
expression | value |
---|---|
(quotient 6 2) | 3 |
(quotient 6 3) | 2 |
(quotient -6 2) | -3 |
(quotient -6 -2) | 3 |
(truncate-quotient 6 2) | 3 |
(truncate-quotient 6 3) | 2 |
(truncate-quotient -6 2) | -3 |
(truncate-quotient -6 -2) | 3 |
(remainder 8 3) | 2 |
(remainder 8 -3) | 2 |
(remainder -8 3) | -2 |
(remainder -8 -3) | -2 |
(truncate-remainder 8 3) | 2 |
(truncate-remainder 8 -3) | 2 |
(truncate-remainder -8 3) | -2 |
(truncate-remainder -8 -3) | -2 |
(modulo 5 1) | 0 |
(modulo 5 2) | 1 |
(modulo 8 3) | 2 |
(modulo 8 -3) | -1 |
(modulo -8 3) | 1 |
(modulo -8 -3) | -2 |
(floor-remainder 5 1) | 0 |
(floor-remainder 5 2) | 1 |
(floor-remainder 5 3) | 2 |
(floor-remainder -5 2) | 1 |
(floor-remainder -5 -2) | -1 |
Calculate a multiplicative inverse
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Calculate an exponentiation
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Calculate a logarithm
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Truncate a number
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
input | output |
---|---|
0 | 0 |
0.1 | 0 |
0.9 | 0 |
1 | 1 |
1.1 | 1 |
1.9 | 1 |
2 | 2 |
-0.9 | 0 |
-1 | -1 |
-1.9 | -1 |
-2 | -2 |
-2.1 | -2 |
Calculate a floor
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
input | output |
---|---|
0 | 0 |
0.1 | 0 |
0.9 | 0 |
1 | 1 |
1.1 | 1 |
1.9 | 1 |
2 | 2 |
-0.9 | -1 |
-1 | -1 |
-1.9 | -2 |
-2 | -2 |
-2.1 | -3 |
Calculate a ceiling
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
input | output |
---|---|
0 | 0 |
0.1 | 1 |
0.9 | 1 |
1 | 1 |
1.1 | 2 |
1.9 | 2 |
2 | 2 |
-0.9 | 0 |
-1 | -1 |
-1.9 | -1 |
-2 | -2 |
-2.1 | -2 |
Round a number
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
input | output |
---|---|
0 | 0 |
0.1 | 0 |
0.49 | 0 |
0.5 | 0 |
0.9 | 1 |
1 | 1 |
1.1 | 1 |
1.49 | 1 |
1.5 | 2 |
1.9 | 2 |
2 | 2 |
2.5 | 2 |
3.5 | 4 |
-1 | -1 |
-0.9 | -1 |
-1.5 | -2 |
-1.51 | -2 |
-1.9 | -2 |
Compare numbers
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
expression |
---|
(< 0 1) |
(< 0 1 2) |
(> 1 0) |
(<= 0 1) |
(<= 0 0) |
(>= 1 0) |
(>= 0 0) |
Compare numbers with an insufficient number of arguments
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
values |
---|
0 |
Calculate a minimum
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
values | output |
---|---|
0 | 0 |
1 | 1 |
1 2 | 1 |
1 2 3 | 1 |
2 3 1 | 1 |
3 1 2 | 1 |
Calculate a maximum
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “A”.
Examples
values | output |
---|---|
0 | 0 |
1 | 1 |
1 2 | 2 |
1 2 3 | 3 |
2 3 1 | 3 |
3 1 2 | 3 |
Convert a number to a string
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
value | radix | output |
---|---|---|
0 | 0 | |
1 | 1 | |
2 | 2 | |
42 | 42 | |
-1 | -1 | |
-2 | -2 | |
-42 | -42 | |
0 | 16 | 0 |
1 | 16 | 1 |
2 | 16 | 2 |
15 | 16 | f |
42 | 16 | 2a |
-1 | 16 | -1 |
-2 | 16 | -2 |
-42 | 16 | -2a |
0 | 32 | 0 |
1 | 32 | 1 |
2 | 32 | 2 |
31 | 32 | v |
42 | 32 | 1a |
-1 | 32 | -1 |
-2 | 32 | -2 |
-42 | 32 | -1a |
Convert a floating point number to a string
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain “<value>”.
Examples
value |
---|
0.5 |
0.125 |
1.2 |
3.14 |
-3.14 |
Convert a string to a number
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<output>”.
Examples
value | radix | output |
---|---|---|
0 | 0 | |
1 | 1 | |
2 | 2 | |
42 | 42 | |
-1 | -1 | |
-2 | -2 | |
-42 | -42 | |
0 | 16 | 0 |
1 | 16 | 1 |
2 | 16 | 2 |
f | 16 | 15 |
2a | 16 | 42 |
2A | 16 | 42 |
-1 | 16 | -1 |
-2 | 16 | -2 |
-2a | 16 | -42 |
-2A | 16 | -42 |
0 | 32 | 0 |
1 | 32 | 1 |
2 | 32 | 2 |
v | 32 | 31 |
1a | 32 | 42 |
1A | 32 | 42 |
-1 | 32 | -1 |
-2 | 32 | -2 |
-1a | 32 | -42 |
-1A | 32 | -42 |
Convert a string to a floating point number
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “<value>”.
Examples
value |
---|
0.5 |
0.125 |
1.2 |
3.14 |
-3.14 |
Convert an invalid string to a number
Given a file named “main.scm” with:
When I successfully run scheme main.scm
Then the stdout should contain exactly “B”.
Examples
value |
---|
x |
foo |
- |
2x |
-x |
-2x |