File: autotests.lua

package info (click to toggle)
naev 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 386,084 kB
  • sloc: ansic: 93,149; xml: 87,292; python: 2,347; sh: 904; makefile: 654; lisp: 162; awk: 4
file content (63 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
--[[
   Some small autotests meant to be used 
--]]

function test_vec2()
   local v, v2
   local fail = 0

   local function vcheck( v, x, y, s )
      local vx, vy = v:get()
      if vx ~= x or vy ~= y then
         print( string.format( '%s) Got %f x %f, expected %f x %f...', s, vx, vy, x, y ) )
         return 1
      end
      return 0
   end

   -- Add test
   v  = vec2.new( 1, 2 )
   v2 = v + vec2.new( 2, 3 )
   v:add( 3, 4 )
   fail = fail + vcheck( v,  1+3, 2+4, 'add: v' )
   fail = fail + vcheck( v2, 1+2, 2+3, 'add: v2' )

   -- Sub test
   v  = vec2.new( 1, 2 )
   v2 = v - vec2.new( 2, 3 )
   v:sub( 3, 4 )
   fail = fail + vcheck( v,  1-3, 2-4, 'sub: v' )
   fail = fail + vcheck( v2, 1-2, 2-3, 'sub: v2' )

   -- Mul test
   v  = vec2.new( 1, 2 )
   v2 = v * 2
   v:mul( 3 )
   fail = fail + vcheck( v,  1*3, 2*3, 'mul: v' )
   fail = fail + vcheck( v2, 1*2, 2*2, 'mul: v2' )

   -- Div test
   v  = vec2.new( 6, 12 )
   v2 = v / 2
   v:div( 3 )
   fail = fail + vcheck( v,  6/3, 12/3, 'div: v' )
   fail = fail + vcheck( v2, 6/2, 12/2, 'div: v2' )

   return fail
end

function run_test( failed, str )
   if failed > 0 then
      print( string.format( "Test '%s' failed %d testcases", str, failed ) )
      return 1
   end
   return 0
end

fail = 0
fail = fail+run_test( test_vec2(), 'vec2' )
if fail==0 then
   print( 'All tests completed successfully!' )
end