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() {
projection := glm.ortho(0, 200, 400, 0)
$if debug {
println(projection.data[0])
}
assert cmp(projection.data[0], 0.01)
assert cmp(projection.data[1], 0.000000)
assert cmp(projection.data[2], 0.000000)
@ -53,18 +55,26 @@ fn test_ortho() {
}
fn test_rotate() {
$if debug {
println('rotate')
}
mut m := glm.identity()
m = glm.scale(m, glm.vec3(2, 2, 2))
$if debug {
println(m)
}
m = glm.rotate_z(m, 1)
$if debug {
println(m)
}
}
fn test_translate() {
mut m := glm.identity()
m = glm.translate(m, glm.vec3(0, 0, - 0.5))
$if debug {
println(m)
}
// TODO
// mat4x4((1.000000, 0.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)
f2 = fractions.fraction(1,3)
sum = f1 + f2
$if debug {
println(sum.f64())
}
assert sum.str().eq('10/3')
f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4)
sum = f1 + f2
$if debug {
println(sum.f64())
}
assert sum.str().eq('19/28')
}
@ -51,12 +55,16 @@ fn test_fraction_subtract() {
f1 = fractions.fraction(9,3)
f2 = fractions.fraction(1,3)
diff = f1 - f2
$if debug {
println(diff.f64())
}
assert diff.str().eq('8/3')
f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4)
diff = f1 - f2
$if debug {
println(diff.f64())
}
assert diff.str().eq('5/28')
}
@ -79,7 +87,9 @@ fn test_fraction_multiply() {
f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4)
product = f1.multiply(f2)
$if debug {
println(product.f64())
}
assert product.str().eq('3/28')
}
@ -102,7 +112,9 @@ fn test_fraction_divide() {
f1 = fractions.fraction(3,7)
f2 = fractions.fraction(1,4)
re = f1.divide(f2)
$if debug {
println(re.f64())
}
assert re.str().eq('12/7')
}

View File

@ -125,7 +125,9 @@ pub fn (s Socket) listen() ?int {
if res < 0 {
return error('socket: listen failed')
}
$if debug {
println('listen res = $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
pub fn listen(port int) ?Socket {
$if debug {
println('net.listen($port)')
}
s := socket(AF_INET, SOCK_STREAM, 0) or {
return error(err)
}
@ -159,7 +163,9 @@ println('net.listen($port)')
// accept first connection request from socket queue
pub fn (s Socket) accept() ?Socket {
$if debug {
println('accept()')
}
addr := C.sockaddr_storage{}
size := 128 // sizeof(sockaddr_storage)
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 {
mut res := ''
for {
$if debug {
println('.')
}
mut buf := malloc(MAX_READ)
n := int(C.recv(s.sockfd, buf, MAX_READ-1, 0))
$if debug {
println('numbytes=$n')
}
if n == -1 {
$if debug {
println('recv failed')
}
// TODO
return ''
}

View File

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