1/*
2 * test2300 - 2300 series of the regress.cal test suite
3 *
4 * Copyright (C) 1999  Landon Curt Noll
5 *
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
9 *
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU Lesser General
13 * Public License for more details.
14 *
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL.  You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 *
20 * Under source code control:	1995/07/09 06:12:13
21 * File existed as early as:	1995
22 *
23 * chongo <was here> /\oo/\	http://www.isthe.com/chongo/
24 * Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/
25 */
26
27
28obj matrix {m}
29
30
31/*
32 * matrix_inc - increment the matrix inside the object
33 */
34define matrix_inc(a)
35{
36	local i;
37
38	/* increment each matrix member */
39	for (i= 0; i < size(a.m); i++)
40		++a.m[[i]];
41	return a;
42}
43
44/*
45 * matrix_dec - decrement the matrix inside the object
46 */
47define matrix_dec(a)
48{
49	local i;
50
51	/* decrement each matrix member */
52	for (i= 0; i < size(a.m); i++)
53		--a.m[[i]];
54	return a;
55}
56
57/*
58 * mkmat - load the matrix inside the object
59 */
60define mkmat()
61{
62	local s, M, i, v;
63
64	/* firewall */
65	s = param(0);
66	if (s == 0)
67		quit "Need at least one argument";
68
69	/* create the matrix */
70	mat M[s];
71
72	/* load the matrix with the args */
73	for (i = 0; i < s; i++)
74		M[i] = param(i + 1);
75
76	/* create the object with the matrix */
77	obj matrix v;
78	v.m = M;
79	return v;
80}
81
82/*
83 * ckmat - check if the matrix inside an object has a set of given values
84 */
85define ckmat()
86{
87	local s, a, i;
88
89	/* firewall */
90	s = param(0);
91	if (s < 2)
92		quit "Need at least two arguments";
93
94	/* get the object to test */
95	a = param(1);
96
97	/* verify the matrix in the object is the right size */
98	if (size(a.m) != s-1) {
99		return 0;
100	}
101
102	/* check each matrix element with the args passed */
103	for (i = 2; i <= s; i++) {
104		if (a.m[i-2] != param(i)) {
105			/* args do not match */
106			return 0;
107		}
108	}
109
110	/* args match the matrix in the object */
111	return 1;
112}
113