Skip to content
Newer
Older
100644 66 lines (53 sloc) 1.05 KB
5bcfee0 @Whiteknight fix the number of functions tests from 8
authored
1 disp("1..6");
84916b5 @Whiteknight initial dump of Matrixy repo from code.google.com/p/matrixy
authored
2
3 % Basic function call with no args
4 function bar
5 printf("ok 1\n");
6 end
7 bar();
8
9 % Function call with 1 arg
10 function foo(x)
11 disp(x);
12 end
13 foo("ok 2");
14
15 % Function call with an alphanumeric name
16 function foo2(x)
17 printf(x);
18 endfunction
19 foo2("ok 3\n");
20
21 % Function call with one return argument and one parameter, but no returned
22 % value
23 function y = foo3(x)
24 printf("%s\n", x);
25 end
26 foo3("ok 4");
27
28 % function with 1 return parameter, and another lexically-scoped variable
29 function y = foo4(x)
30 y = 5;
31 r = 100;
32 end
33 myret = foo4("dummy");
34 if myret == 5
35 printf("ok 5\n");
36 else
37 printf("not ok 5\n");
38 endif
39
40 % Test a combination of functions, including calling functions from functions
41 % and using function output arguments as inputs to other functions.
42 function pi2
43 return 3.14;
44 end
45
46 function c = circum(r)
47 c = double( pi2() * r );
48 end
49
50 function d = double(x)
51 d = 2 * x;
52 end
53
54 function z = ten()
55 z = 10;
56 end
57
58 x = double(circum(ten() * 5));
59
60 if x == 200 * pi2()
61 printf("ok 6\n");
62 else
63 printf("not ok 6\n");
64 endif
65
Something went wrong with that request. Please try again.