tests: cleanup

pull/1682/head
Carlos Esquerdo Bernat 2019-08-20 10:18:12 +02:00 committed by Alexander Medvednikov
parent dee411149e
commit cf23c289ec
6 changed files with 65 additions and 23 deletions

View File

@ -12,7 +12,9 @@ fn cmp(a, b f32) bool {
fn test_ortho() { fn test_ortho() {
projection := glm.ortho(0, 200, 400, 0) projection := glm.ortho(0, 200, 400, 0)
$if debug {
println(projection.data[0]) println(projection.data[0])
}
assert cmp(projection.data[0], 0.01) assert cmp(projection.data[0], 0.01)
assert cmp(projection.data[1], 0.000000) assert cmp(projection.data[1], 0.000000)
assert cmp(projection.data[2], 0.000000) assert cmp(projection.data[2], 0.000000)
@ -53,18 +55,26 @@ fn test_ortho() {
} }
fn test_rotate() { fn test_rotate() {
$if debug {
println('rotate') println('rotate')
}
mut m := glm.identity() mut m := glm.identity()
m = glm.scale(m, glm.vec3(2, 2, 2)) m = glm.scale(m, glm.vec3(2, 2, 2))
$if debug {
println(m) println(m)
}
m = glm.rotate_z(m, 1) m = glm.rotate_z(m, 1)
$if debug {
println(m) println(m)
} }
}
fn test_translate() { fn test_translate() {
mut m := glm.identity() mut m := glm.identity()
m = glm.translate(m, glm.vec3(0, 0, - 0.5)) m = glm.translate(m, glm.vec3(0, 0, - 0.5))
$if debug {
println(m) println(m)
}
// TODO // TODO
// mat4x4((1.000000, 0.000000, 0.000000, 0.000000), // mat4x4((1.000000, 0.000000, 0.000000, 0.000000),
// (0.000000, 1.000000, 0.000000, 0.000000), // (0.000000, 1.000000, 0.000000, 0.000000),

View File

@ -28,12 +28,16 @@ fn test_fraction_add() {
f1 = fractions.fraction(9,3) f1 = fractions.fraction(9,3)
f2 = fractions.fraction(1,3) f2 = fractions.fraction(1,3)
sum = f1 + f2 sum = f1 + f2
$if debug {
println(sum.f64()) println(sum.f64())
}
assert sum.str().eq('10/3') assert sum.str().eq('10/3')
f1 = fractions.fraction(3,7) f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4) f2 = fractions.fraction(1,4)
sum = f1 + f2 sum = f1 + f2
$if debug {
println(sum.f64()) println(sum.f64())
}
assert sum.str().eq('19/28') assert sum.str().eq('19/28')
} }
@ -51,12 +55,16 @@ fn test_fraction_subtract() {
f1 = fractions.fraction(9,3) f1 = fractions.fraction(9,3)
f2 = fractions.fraction(1,3) f2 = fractions.fraction(1,3)
diff = f1 - f2 diff = f1 - f2
$if debug {
println(diff.f64()) println(diff.f64())
}
assert diff.str().eq('8/3') assert diff.str().eq('8/3')
f1 = fractions.fraction(3,7) f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4) f2 = fractions.fraction(1,4)
diff = f1 - f2 diff = f1 - f2
$if debug {
println(diff.f64()) println(diff.f64())
}
assert diff.str().eq('5/28') assert diff.str().eq('5/28')
} }
@ -79,7 +87,9 @@ fn test_fraction_multiply() {
f1 = fractions.fraction(3,7) f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4) f2 = fractions.fraction(1,4)
product = f1.multiply(f2) product = f1.multiply(f2)
$if debug {
println(product.f64()) println(product.f64())
}
assert product.str().eq('3/28') assert product.str().eq('3/28')
} }
@ -102,7 +112,9 @@ fn test_fraction_divide() {
f1 = fractions.fraction(3,7) f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4) f2 = fractions.fraction(1,4)
re = f1.divide(f2) re = f1.divide(f2)
$if debug {
println(re.f64()) println(re.f64())
}
assert re.str().eq('12/7') assert re.str().eq('12/7')
} }

View File

@ -125,7 +125,9 @@ pub fn (s Socket) listen() ?int {
if res < 0 { if res < 0 {
return error('socket: listen failed') return error('socket: listen failed')
} }
$if debug {
println('listen res = $res') println('listen res = $res')
}
return res return res
} }
@ -144,7 +146,9 @@ pub fn (s Socket) listen_backlog(backlog int) ?int {
// helper method to create, bind, and listen given port number // helper method to create, bind, and listen given port number
pub fn listen(port int) ?Socket { pub fn listen(port int) ?Socket {
$if debug {
println('net.listen($port)') println('net.listen($port)')
}
s := socket(AF_INET, SOCK_STREAM, 0) or { s := socket(AF_INET, SOCK_STREAM, 0) or {
return error(err) return error(err)
} }
@ -159,7 +163,9 @@ println('net.listen($port)')
// accept first connection request from socket queue // accept first connection request from socket queue
pub fn (s Socket) accept() ?Socket { pub fn (s Socket) accept() ?Socket {
$if debug {
println('accept()') println('accept()')
}
addr := C.sockaddr_storage{} addr := C.sockaddr_storage{}
size := 128 // sizeof(sockaddr_storage) size := 128 // sizeof(sockaddr_storage)
sockfd := C.accept(s.sockfd, &addr, &size) sockfd := C.accept(s.sockfd, &addr, &size)
@ -265,12 +271,18 @@ pub fn (s Socket) write(str string) {
pub fn (s Socket) read_line() string { pub fn (s Socket) read_line() string {
mut res := '' mut res := ''
for { for {
$if debug {
println('.') println('.')
}
mut buf := malloc(MAX_READ) mut buf := malloc(MAX_READ)
n := int(C.recv(s.sockfd, buf, MAX_READ-1, 0)) n := int(C.recv(s.sockfd, buf, MAX_READ-1, 0))
$if debug {
println('numbytes=$n') println('numbytes=$n')
}
if n == -1 { if n == -1 {
$if debug {
println('recv failed') println('recv failed')
}
// TODO // TODO
return '' return ''
} }

View File

@ -126,7 +126,9 @@ pub fn run<T>(port int) {
method: vals[0] method: vals[0]
url: vals[1] url: vals[1]
} }
$if debug {
println('vweb action = "$action"') println('vweb action = "$action"')
}
//mut app := T{ //mut app := T{
app.vweb = Context{ app.vweb = Context{
req: req req: req
@ -140,7 +142,9 @@ pub fn run<T>(port int) {
app.vweb.parse_form(s) app.vweb.parse_form(s)
} }
if vals.len < 2 { if vals.len < 2 {
$if debug {
println('no vals for http') println('no vals for http')
}
conn.close() conn.close()
continue continue
} }
@ -173,14 +177,18 @@ fn (ctx mut Context) parse_form(s string) {
str_form = str_form.replace('+', ' ') str_form = str_form.replace('+', ' ')
words := str_form.split('&') words := str_form.split('&')
for word in words { for word in words {
$if debug {
println('parse form keyval="$word"') println('parse form keyval="$word"')
}
keyval := word.trim_space().split('=') keyval := word.trim_space().split('=')
if keyval.len != 2 { continue } if keyval.len != 2 { continue }
key := keyval[0] key := keyval[0]
val := urllib.query_unescape(keyval[1]) or { val := urllib.query_unescape(keyval[1]) or {
continue continue
} }
$if debug {
println('http form "$key" => "$val"') println('http form "$key" => "$val"')
}
ctx.form[key] = val ctx.form[key] = val
} }
} }