summaryrefslogtreecommitdiff
path: root/tests/general/extlvals.icn
blob: 0f394ba5125acf8ff170963db509f3e3967e83ad (plain)
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
64
65
66
67
68
69
70
71
#  Test use of external values with dynamic loading, using demo cfunc.

link cfunc

record complex(r, i)

procedure main()
   local e, l, v1, v2, v3, v4
   local r1,r2,r3,r4, s1, s2, s3, s4

   # test simple creation, type(), copy()
   xwrite("v1", v1 := extxmin())
   xwrite("v2", v2 := extxmin())
   xwrite("v3", v3 := v1)
   xwrite("v4", v4 := copy(v1))

   # test string-based external example
   xwrite("s1", s1 := extxstr("bite"))
   xwrite("s2", s2 := extxstr("the"))
   xwrite("s3", s3 := extxstr("wax"))
   xwrite("s4", s4 := extxstr("tadpole"))

   # test real-based external example
   xwrite("r1", r1 := extxreal(111.1))
   xwrite("r2", r2 := extxreal(222.2))
   xwrite("r3", r3 := extxreal(333.3))
   xwrite("r4", r4 := copy(r1))

   # test === and ~===
   teqv(v1, v3, v2)
   teqv(v1, v4, v2)
   teqv(s2, copy(s2), s3)
   teqv(r1, r1, copy(r1))
   teqv(s1, s1, s3)
   teqv(r2, r2, r4)
   teqv(s3, s3, r3)

   # test sorting
   l := [ v1, s2, r3, v4, s1, r2, complex(8,9), v3, s4, r1, v2, s3, r4 ]
   write()
   every xwrite("before", !l)
   write()
   every xwrite("sorted", !sort(l))

end


#  write label, type(xval), image(xval)

procedure xwrite(label, xval)
   write(label, ": ", type(xval), ": ",image(xval))
   return
end


#  test equivalence of id1 and id2, and nonequivalence of diff

procedure teqv(id1, id2, diff)
   if id1 ~=== id2 then
      write("nonequivalent: ", image(id1), " and ", image(id2))
   if id2 ~=== id1 then
      write("nonequivalent: ", image(id2), " and ", image(id1))
   if not (id1 === id2) then
      write("not equivalent: ", image(id1), " and ", image(id2))

   if id1 === diff then
      write("false equivalence: ", image(id1), " and ", image(diff))
   if id2 === diff then
      write("false equivalence: ", image(id2), " and ", image(diff))
   return
end