vile / scheme / small_product393_test.v
43 lines · 40 sloc · 1.68 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3import os
4import strconv
5
6fn test_small_product_matches_independent_signed_boundary_and_random_oracles() {
7 fixture := os.read_file(os.join_path(os.dir(@FILE), 'testdata', 'small_product393.tsv'))!
8 mut checked := 0
9 for line in fixture.split_into_lines() {
10 if line == '' || line[0] == `#` { continue }
11 row := line.split('\t')
12 assert row.len == 4, line
13 a := strconv.parse_int(row[0], 10, 64)!
14 b := strconv.parse_int(row[1], 10, 64)!
15 if product := small_multiply(a, b) {
16 assert row[3] == 'integer' && product.str() == row[2], line
17 } else {
18 assert row[3] == 'big_integer', line
19 }
20 boxed := numeric_multiply(integer(a), integer(b))!
21 assert write(boxed)! == row[2], line
22 assert boxed.tag == if row[3] == 'integer' { Kind.integer } else { Kind.big_integer }, line
23 checked++
24 }
25 assert checked == 6869
26}
27
28fn test_small_product_boundary_promotion_keeps_both_frontends_and_live_operators() {
29 mut vm := new_with_options(Options{max_steps: 0, max_frames: 0})!
30 for source, expected in {
31 '(* -9223372036854775808 1)': '-9223372036854775808'
32 '(* -9223372036854775808 -1)': '9223372036854775808'
33 '(* -9223372036854775808 0)': '0'
34 '(* 3037000499 3037000499)': '9223372030926249001'
35 '(* 3037000500 3037000500)': '9223372037000250000'
36 '(* -9223372036854775808 -9223372036854775808)': '85070591730234615865843651857942052864'
37 } { assert write(vm.eval(source)!)! == expected, source }
38 assert write(vm.eval_alt('left := -9223372036854775808\nleft * -1')!)! == '9223372036854775808'
39 vm.eval('(define product *)(define(f a b)(product a b))')!
40 assert vm.eval('(f -9223372036854775808 1)')!.whole() == exact_min
41 vm.eval('(set! product +)')!
42 assert vm.eval('(f 6 7)')!.whole() == 13
43}
44