separate number into float and integer
This commit is contained in:
parent
10f55313b0
commit
daab50d54c
22 changed files with 848 additions and 428 deletions
|
|
@ -1,5 +1,5 @@
|
|||
assertEq(1+1, 2)
|
||||
assertEq(3*2, 6)
|
||||
assertEq(3/4, 0.75)
|
||||
assertEq(3.0/4.0, 0.75)
|
||||
assertEq(2 - 5, -3)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ assertEq(1, 1)
|
|||
assertEq(0, 0)
|
||||
assertEq("", "")
|
||||
|
||||
assertEq([]number, []number)
|
||||
assertEq([]int, []int)
|
||||
assertEq([3, 1, 4, 1], [3, 1, 4, 1])
|
||||
|
||||
# Inequality
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
list := []number
|
||||
list := []int
|
||||
|
||||
x := 1
|
||||
while x <= 1000 {
|
||||
list.append(x)
|
||||
assertEq(list.reduce(func(tot: number, a: number) number {
|
||||
assertEq(list.reduce(fn(tot: int, a: int) -> int {
|
||||
return tot + a
|
||||
}, 0), x*(x + 1)/2)
|
||||
|
||||
x = x + 1
|
||||
}
|
||||
|
||||
func sum(a: number, b: number) number {
|
||||
fn sum(a: int, b: int) -> int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
list = []number
|
||||
list = []int
|
||||
x = 1
|
||||
while x <= 100 {
|
||||
list.append(2*x - 1)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ fibonacci_numbers := [
|
|||
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
|
||||
]
|
||||
|
||||
func fib(n: number) number {
|
||||
fn fib(n: int) -> int {
|
||||
if n < 2 {
|
||||
return n
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
list := []number
|
||||
list := []int
|
||||
|
||||
list.append(1)
|
||||
list.append(2)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
|
||||
func sum(a: number, b: number) number {
|
||||
fn sum(a: int, b: int) -> int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
breakpoint
|
||||
|
||||
assertEq(sum(1, 2), 3)
|
||||
breakpoint
|
||||
|
||||
assertEq(sum(3, 3), 6)
|
||||
breakpoint
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
assertEq(type(1), "number")
|
||||
assertEq(type(1), "int")
|
||||
assertEq(type("Hello"), "string")
|
||||
assertEq(type(true), "boolean")
|
||||
|
||||
# lists
|
||||
assertEq(type(["Hello", "world"]), "list[string]")
|
||||
assertEq(type([0, 1]), "list[number]")
|
||||
assertEq(type([0, 1]), "list[int]")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue