Skip to content

Commit b26f63b

Browse files
committed
improved test coverage
1 parent f1e78d5 commit b26f63b

File tree

2 files changed

+141
-5
lines changed

2 files changed

+141
-5
lines changed

tests/org/cicirello/math/la/LinearAlgebraTests.java

Lines changed: 140 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Vincent A. Cicirello, <https://www.cicirello.org/>.
2+
* Copyright 2018-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
33
*
44
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
55
*
@@ -47,6 +47,10 @@ public void testTransposeInts() {
4747
}
4848
}
4949
}
50+
IllegalArgumentException thrown = assertThrows(
51+
IllegalArgumentException.class,
52+
() -> MatrixOps.transposeSquareMatrixInline(new int[1][2])
53+
);
5054
}
5155

5256
@Test
@@ -62,6 +66,10 @@ public void testTransposeDoubles() {
6266
}
6367
}
6468
}
69+
IllegalArgumentException thrown = assertThrows(
70+
IllegalArgumentException.class,
71+
() -> MatrixOps.transposeSquareMatrixInline(new double[1][2])
72+
);
6573
}
6674

6775
@Test
@@ -97,6 +105,26 @@ public void testSumInts() {
97105
}
98106
}
99107
}
108+
IllegalArgumentException thrown = assertThrows(
109+
IllegalArgumentException.class,
110+
() -> MatrixOps.sum(new int[1][2], new int[2][2])
111+
);
112+
thrown = assertThrows(
113+
IllegalArgumentException.class,
114+
() -> MatrixOps.sum(new int[1][2], new int[1][1])
115+
);
116+
thrown = assertThrows(
117+
IllegalArgumentException.class,
118+
() -> MatrixOps.sum(new int[1][1], new int[1][1], new int[1][2])
119+
);
120+
thrown = assertThrows(
121+
IllegalArgumentException.class,
122+
() -> MatrixOps.sum(new int[1][1], new int[1][1], new int[2][1])
123+
);
124+
thrown = assertThrows(
125+
IllegalArgumentException.class,
126+
() -> MatrixOps.sum(new int[0][0], new int[0][0], new int[1][2])
127+
);
100128
}
101129

102130
@Test
@@ -114,7 +142,7 @@ public void testSumDoubles() {
114142
}
115143
}
116144
c = null;
117-
c = MatrixOps.sum(a,b,null);
145+
c = MatrixOps.sum(a,b);
118146
assertEquals("result rows",n, c.length);
119147
if (n > 0) assertEquals("result cols", m, c[0].length);
120148
for (int i = 0; i < n; i++) {
@@ -132,6 +160,26 @@ public void testSumDoubles() {
132160
}
133161
}
134162
}
163+
IllegalArgumentException thrown = assertThrows(
164+
IllegalArgumentException.class,
165+
() -> MatrixOps.sum(new double[1][2], new double[2][2])
166+
);
167+
thrown = assertThrows(
168+
IllegalArgumentException.class,
169+
() -> MatrixOps.sum(new double[1][2], new double[1][1])
170+
);
171+
thrown = assertThrows(
172+
IllegalArgumentException.class,
173+
() -> MatrixOps.sum(new double[1][1], new double[1][1], new double[1][2])
174+
);
175+
thrown = assertThrows(
176+
IllegalArgumentException.class,
177+
() -> MatrixOps.sum(new double[1][1], new double[1][1], new double[2][1])
178+
);
179+
thrown = assertThrows(
180+
IllegalArgumentException.class,
181+
() -> MatrixOps.sum(new double[0][0], new double[0][0], new double[1][2])
182+
);
135183
}
136184

137185
@Test
@@ -151,7 +199,7 @@ public void testDifferenceInts() {
151199
}
152200
}
153201
c = null;
154-
c = MatrixOps.difference(a,b,null);
202+
c = MatrixOps.difference(a,b);
155203
assertEquals("result rows",n, c.length);
156204
if (n > 0) assertEquals("result cols", m, c[0].length);
157205
k = 1;
@@ -173,6 +221,26 @@ public void testDifferenceInts() {
173221
}
174222
}
175223
}
224+
IllegalArgumentException thrown = assertThrows(
225+
IllegalArgumentException.class,
226+
() -> MatrixOps.difference(new int[1][2], new int[2][2])
227+
);
228+
thrown = assertThrows(
229+
IllegalArgumentException.class,
230+
() -> MatrixOps.difference(new int[1][2], new int[1][1])
231+
);
232+
thrown = assertThrows(
233+
IllegalArgumentException.class,
234+
() -> MatrixOps.difference(new int[1][1], new int[1][1], new int[1][2])
235+
);
236+
thrown = assertThrows(
237+
IllegalArgumentException.class,
238+
() -> MatrixOps.difference(new int[1][1], new int[1][1], new int[2][1])
239+
);
240+
thrown = assertThrows(
241+
IllegalArgumentException.class,
242+
() -> MatrixOps.difference(new int[0][0], new int[0][0], new int[1][2])
243+
);
176244
}
177245

178246
@Test
@@ -192,7 +260,7 @@ public void testDifferenceDoubles() {
192260
}
193261
}
194262
c = null;
195-
c = MatrixOps.difference(a,b,null);
263+
c = MatrixOps.difference(a,b);
196264
assertEquals("result rows",n, c.length);
197265
if (n > 0) assertEquals("result cols", m, c[0].length);
198266
k = 1;
@@ -214,6 +282,26 @@ public void testDifferenceDoubles() {
214282
}
215283
}
216284
}
285+
IllegalArgumentException thrown = assertThrows(
286+
IllegalArgumentException.class,
287+
() -> MatrixOps.difference(new double[1][2], new double[2][2])
288+
);
289+
thrown = assertThrows(
290+
IllegalArgumentException.class,
291+
() -> MatrixOps.difference(new double[1][2], new double[1][1])
292+
);
293+
thrown = assertThrows(
294+
IllegalArgumentException.class,
295+
() -> MatrixOps.difference(new double[1][1], new double[1][1], new double[1][2])
296+
);
297+
thrown = assertThrows(
298+
IllegalArgumentException.class,
299+
() -> MatrixOps.difference(new double[1][1], new double[1][1], new double[2][1])
300+
);
301+
thrown = assertThrows(
302+
IllegalArgumentException.class,
303+
() -> MatrixOps.difference(new double[0][0], new double[0][0], new double[1][2])
304+
);
217305
}
218306

219307
@Test
@@ -390,6 +478,30 @@ public void testProductInt() {
390478
}
391479
}
392480
}
481+
IllegalArgumentException thrown = assertThrows(
482+
IllegalArgumentException.class,
483+
() -> MatrixOps.product(new int[1][2], new int[1][2])
484+
);
485+
thrown = assertThrows(
486+
IllegalArgumentException.class,
487+
() -> MatrixOps.product(new int[0][1], new int[1][2])
488+
);
489+
thrown = assertThrows(
490+
IllegalArgumentException.class,
491+
() -> MatrixOps.product(new int[1][1], new int[0][2])
492+
);
493+
thrown = assertThrows(
494+
IllegalArgumentException.class,
495+
() -> MatrixOps.product(new int[1][1], new int[1][1], new int[1][2])
496+
);
497+
thrown = assertThrows(
498+
IllegalArgumentException.class,
499+
() -> MatrixOps.product(new int[1][1], new int[1][1], new int[2][1])
500+
);
501+
thrown = assertThrows(
502+
IllegalArgumentException.class,
503+
() -> MatrixOps.product(new int[0][0], new int[0][0], new int[1][2])
504+
);
393505
}
394506

395507
@Test
@@ -435,6 +547,30 @@ public void testProductDouble() {
435547
}
436548
}
437549
}
550+
IllegalArgumentException thrown = assertThrows(
551+
IllegalArgumentException.class,
552+
() -> MatrixOps.product(new double[1][2], new double[1][2])
553+
);
554+
thrown = assertThrows(
555+
IllegalArgumentException.class,
556+
() -> MatrixOps.product(new double[0][1], new double[1][2])
557+
);
558+
thrown = assertThrows(
559+
IllegalArgumentException.class,
560+
() -> MatrixOps.product(new double[1][1], new double[0][2])
561+
);
562+
thrown = assertThrows(
563+
IllegalArgumentException.class,
564+
() -> MatrixOps.product(new double[1][1], new double[1][1], new double[1][2])
565+
);
566+
thrown = assertThrows(
567+
IllegalArgumentException.class,
568+
() -> MatrixOps.product(new double[1][1], new double[1][1], new double[2][1])
569+
);
570+
thrown = assertThrows(
571+
IllegalArgumentException.class,
572+
() -> MatrixOps.product(new double[0][0], new double[0][0], new double[1][2])
573+
);
438574
}
439575

440576
@Test

tests/org/cicirello/math/rand/RandomVariatesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
2+
* Copyright 2019-2021 Vincent A. Cicirello, <https://www.cicirello.org/>.
33
*
44
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
55
*

0 commit comments

Comments
 (0)