How to use assertArrayEquals method of org.junit.Assert class

Best junit code snippet using org.junit.Assert.assertArrayEquals

Source:AssertionTest.java Github

copy

Full Screen

1package org.junit.tests.assertion;2import static org.hamcrest.CoreMatchers.equalTo;3import static org.hamcrest.CoreMatchers.instanceOf;4import static org.hamcrest.CoreMatchers.is;5import static org.junit.Assert.assertArrayEquals;6import static org.junit.Assert.assertEquals;7import static org.junit.Assert.assertNotEquals;8import static org.junit.Assert.assertNotSame;9import static org.junit.Assert.assertNull;10import static org.junit.Assert.assertSame;11import static org.junit.Assert.assertThat;12import static org.junit.Assert.assertTrue;13import static org.junit.Assert.fail;14import java.math.BigDecimal;15import org.junit.Assert;16import org.junit.ComparisonFailure;17import org.junit.Test;18import org.junit.internal.ArrayComparisonFailure;19/**20 * Tests for {@link org.junit.Assert}21 */22public class AssertionTest {23// If you want to use 1.4 assertions, they will be reported correctly.24// However, you need to add the -ea VM argument when running.25// @Test (expected=AssertionError.class) public void error() {26// assert false;27// }28 @Test(expected = AssertionError.class)29 public void fails() {30 Assert.fail();31 }32 @Test33 public void failWithNoMessageToString() {34 try {35 Assert.fail();36 } catch (AssertionError exception) {37 assertEquals("java.lang.AssertionError", exception.toString());38 }39 }40 @Test41 public void failWithMessageToString() {42 try {43 Assert.fail("woops!");44 } catch (AssertionError exception) {45 assertEquals("java.lang.AssertionError: woops!", exception.toString());46 }47 }48 @Test(expected = AssertionError.class)49 public void arraysNotEqual() {50 assertArrayEquals((new Object[]{new Object()}), (new Object[]{new Object()}));51 }52 @Test(expected = AssertionError.class)53 public void arraysNotEqualWithMessage() {54 assertArrayEquals("not equal", (new Object[]{new Object()}), (new Object[]{new Object()}));55 }56 @Test57 public void arraysExpectedNullMessage() {58 try {59 assertArrayEquals("not equal", null, (new Object[]{new Object()}));60 } catch (AssertionError exception) {61 assertEquals("not equal: expected array was null", exception.getMessage());62 }63 }64 @Test65 public void arraysActualNullMessage() {66 try {67 assertArrayEquals("not equal", (new Object[]{new Object()}), null);68 } catch (AssertionError exception) {69 assertEquals("not equal: actual array was null", exception.getMessage());70 }71 }72 @Test73 public void arraysDifferentLengthMessage() {74 try {75 assertArrayEquals("not equal", (new Object[0]), (new Object[1]));76 } catch (AssertionError exception) {77 assertEquals("not equal: array lengths differed, expected.length=0 actual.length=1", exception.getMessage());78 }79 }80 @Test(expected = ArrayComparisonFailure.class)81 public void arraysElementsDiffer() {82 assertArrayEquals("not equal", (new Object[]{"this is a very long string in the middle of an array"}), (new Object[]{"this is another very long string in the middle of an array"}));83 }84 @Test85 public void arraysDifferAtElement0nullMessage() {86 try {87 assertArrayEquals((new Object[]{true}), (new Object[]{false}));88 } catch (AssertionError exception) {89 assertEquals("arrays first differed at element [0]; expected:<true> but was:<false>", exception90 .getMessage());91 }92 }93 @Test94 public void arraysDifferAtElement1nullMessage() {95 try {96 assertArrayEquals((new Object[]{true, true}), (new Object[]{true,97 false}));98 } catch (AssertionError exception) {99 assertEquals("arrays first differed at element [1]; expected:<true> but was:<false>", exception100 .getMessage());101 }102 }103 @Test104 public void arraysDifferAtElement0withMessage() {105 try {106 assertArrayEquals("message", (new Object[]{true}), (new Object[]{false}));107 } catch (AssertionError exception) {108 assertEquals("message: arrays first differed at element [0]; expected:<true> but was:<false>", exception109 .getMessage());110 }111 }112 @Test113 public void arraysDifferAtElement1withMessage() {114 try {115 assertArrayEquals("message", (new Object[]{true, true}), (new Object[]{true, false}));116 fail();117 } catch (AssertionError exception) {118 assertEquals("message: arrays first differed at element [1]; expected:<true> but was:<false>", exception.getMessage());119 }120 }121 @Test122 public void multiDimensionalArraysAreEqual() {123 assertArrayEquals((new Object[][]{{true, true}, {false, false}}), (new Object[][]{{true, true}, {false, false}}));124 }125 @Test126 public void multiDimensionalIntArraysAreEqual() {127 int[][] int1 = {{1, 2, 3}, {4, 5, 6}};128 int[][] int2 = {{1, 2, 3}, {4, 5, 6}};129 assertArrayEquals(int1, int2);130 }131 @Test132 public void oneDimensionalPrimitiveArraysAreEqual() {133 assertArrayEquals(new byte[]{1}, new byte[]{1});134 assertArrayEquals(new char[]{1}, new char[]{1});135 assertArrayEquals(new short[]{1}, new short[]{1});136 assertArrayEquals(new int[]{1}, new int[]{1});137 assertArrayEquals(new long[]{1}, new long[]{1});138 assertArrayEquals(new double[]{1.0}, new double[]{1.0}, 1.0);139 assertArrayEquals(new float[]{1.0f}, new float[]{1.0f}, 1.0f);140 }141 @Test(expected = AssertionError.class)142 public void oneDimensionalDoubleArraysAreNotEqual() {143 assertArrayEquals(new double[]{1.0}, new double[]{2.5}, 1.0);144 }145 @Test(expected = AssertionError.class)146 public void oneDimensionalFloatArraysAreNotEqual() {147 assertArrayEquals(new float[]{1.0f}, new float[]{2.5f}, 1.0f);148 }149 @Test(expected = AssertionError.class)150 public void IntegerDoesNotEqualLong() {151 assertEquals(new Integer(1), new Long(1));152 }153 @Test154 public void intsEqualLongs() {155 assertEquals(1, 1L);156 }157 @Test158 public void multiDimensionalArraysDeclaredAsOneDimensionalAreEqual() {159 assertArrayEquals((new Object[]{new Object[]{true, true}, new Object[]{false, false}}), (new Object[]{new Object[]{true, true}, new Object[]{false, false}}));160 }161 @Test162 public void multiDimensionalArraysAreNotEqual() {163 try {164 assertArrayEquals("message", (new Object[][]{{true, true}, {false, false}}), (new Object[][]{{true, true}, {true, false}}));165 fail();166 } catch (AssertionError exception) {167 assertEquals("message: arrays first differed at element [1][0]; expected:<false> but was:<true>", exception.getMessage());168 }169 }170 @Test171 public void multiDimensionalArraysAreNotEqualNoMessage() {172 try {173 assertArrayEquals((new Object[][]{{true, true}, {false, false}}), (new Object[][]{{true, true}, {true, false}}));174 fail();175 } catch (AssertionError exception) {176 assertEquals("arrays first differed at element [1][0]; expected:<false> but was:<true>", exception.getMessage());177 }178 }179 @Test180 public void arraysWithNullElementEqual() {181 Object[] objects1 = new Object[]{null};182 Object[] objects2 = new Object[]{null};183 assertArrayEquals(objects1, objects2);184 }185 @Test186 public void stringsDifferWithUserMessage() {187 try {188 assertEquals("not equal", "one", "two");189 } catch (Throwable exception) {190 assertEquals("not equal expected:<[one]> but was:<[two]>", exception.getMessage());191 }192 }193 @Test194 public void arraysEqual() {195 Object element = new Object();196 Object[] objects1 = new Object[]{element};197 Object[] objects2 = new Object[]{element};198 assertArrayEquals(objects1, objects2);199 }200 @Test201 public void arraysEqualWithMessage() {202 Object element = new Object();203 Object[] objects1 = new Object[]{element};204 Object[] objects2 = new Object[]{element};205 assertArrayEquals("equal", objects1, objects2);206 }207 @Test208 public void equals() {209 Object o = new Object();210 assertEquals(o, o);211 assertEquals("abc", "abc");212 assertEquals(true, true);213 assertEquals((byte) 1, (byte) 1);214 assertEquals('a', 'a');215 assertEquals((short) 1, (short) 1);216 assertEquals(1, 1); // int by default, cast is unnecessary217 assertEquals(1l, 1l);218 assertEquals(1.0, 1.0, 0.0);219 assertEquals(1.0d, 1.0d, 0.0d);220 }221 @Test(expected = AssertionError.class)222 public void notEqualsObjectWithNull() {223 assertEquals(new Object(), null);224 }225 @Test(expected = AssertionError.class)226 public void notEqualsNullWithObject() {227 assertEquals(null, new Object());228 }229 @Test230 public void notEqualsObjectWithNullWithMessage() {231 Object o = new Object();232 try {233 assertEquals("message", null, o);234 fail();235 } catch (AssertionError e) {236 assertEquals("message expected:<null> but was:<" + o.toString() + ">", e.getMessage());237 }238 }239 @Test240 public void notEqualsNullWithObjectWithMessage() {241 Object o = new Object();242 try {243 assertEquals("message", o, null);244 fail();245 } catch (AssertionError e) {246 assertEquals("message expected:<" + o.toString() + "> but was:<null>", e.getMessage());247 }248 }249 @Test(expected = AssertionError.class)250 public void objectsNotEquals() {251 assertEquals(new Object(), new Object());252 }253 @Test(expected = ComparisonFailure.class)254 public void stringsNotEqual() {255 assertEquals("abc", "def");256 }257 @Test(expected = AssertionError.class)258 public void booleansNotEqual() {259 assertEquals(true, false);260 }261 @Test(expected = AssertionError.class)262 public void bytesNotEqual() {263 assertEquals((byte) 1, (byte) 2);264 }265 @Test(expected = AssertionError.class)266 public void charsNotEqual() {267 assertEquals('a', 'b');268 }269 @Test(expected = AssertionError.class)270 public void shortsNotEqual() {271 assertEquals((short) 1, (short) 2);272 }273 @Test(expected = AssertionError.class)274 public void intsNotEqual() {275 assertEquals(1, 2);276 }277 @Test(expected = AssertionError.class)278 public void longsNotEqual() {279 assertEquals(1l, 2l);280 }281 @Test(expected = AssertionError.class)282 public void floatsNotEqual() {283 assertEquals(1.0, 2.0, 0.9);284 }285 @SuppressWarnings("deprecation")286 @Test(expected = AssertionError.class)287 public void floatsNotEqualWithoutDelta() {288 assertEquals(1.0, 1.1);289 }290 @Test291 public void floatsNotDoublesInArrays() {292 float delta = 4.444f;293 float[] f1 = new float[]{1.111f};294 float[] f2 = new float[]{5.555f};295 Assert.assertArrayEquals(f1, f2, delta);296 }297 @Test(expected = AssertionError.class)298 public void bigDecimalsNotEqual() {299 assertEquals(new BigDecimal("123.4"), new BigDecimal("123.0"));300 }301 @Test(expected = AssertionError.class)302 public void doublesNotEqual() {303 assertEquals(1.0d, 2.0d, 0.9d);304 }305 @Test306 public void naNsAreEqual() {307 assertEquals(Float.NaN, Float.NaN, Float.POSITIVE_INFINITY);308 assertEquals(Double.NaN, Double.NaN, Double.POSITIVE_INFINITY);309 }...

Full Screen

Full Screen

Source:QuasiLatinSquaresSysTest.java Github

copy

Full Screen

...13 }14 15 @Test16 public void test0(){17 assertArrayEquals(new String[]{"0 1 2", "1 2 0", "2 0 1"}, solver.makeSquare(3,3) );18 }19 @Test20 public void test1(){21 assertArrayEquals(new String[]{"0 0 0 0 1", "0 0 0 0 1", "0 0 0 0 1", "0 0 0 0 1", "1 1 1 1 0"}, solver.makeSquare(5,2) );22 }23 @Test24 public void test2(){25 assertArrayEquals(new String[]{"0 0 1 2 3", "0 0 1 2 3", "1 1 0 3 2", "2 2 3 0 1", "3 3 2 1 0"}, solver.makeSquare(5,4) );26 }27 @Test28 public void test3(){29 assertArrayEquals(new String[]{"0 0 0 1 2 3 4 5 6", "0 0 0 1 2 3 4 5 6", "0 0 0 1 2 3 4 5 6", "1 1 1 0 3 2 5 6 4", "2 2 2 3 0 1 6 4 5", "3 3 3 4 5 6 0 1 2", "4 4 4 2 6 5 1 0 3", "5 5 5 6 1 4 2 3 0", "6 6 6 5 4 0 3 2 1"}, solver.makeSquare(9,7) );30 }31 @Test32 public void test4(){33 assertArrayEquals(new String[]{"0 1 2 3 4 5 6 7 8 9", "1 0 3 2 5 4 7 6 9 8", "2 3 0 1 6 7 8 9 4 5", "3 2 1 0 7 6 9 8 5 4", "4 5 6 7 8 9 0 1 2 3", "5 4 7 6 9 8 1 0 3 2", "6 7 8 9 2 3 4 5 0 1", "7 6 9 8 3 2 5 4 1 0", "8 9 4 5 0 1 2 3 6 7", "9 8 5 4 1 0 3 2 7 6"}, solver.makeSquare(10,10) );34 }35 @Test36 public void test5(){37 assertArrayEquals(new String[]{"0"}, solver.makeSquare(1,1) );38 }39 @Test40 public void test6(){41 assertArrayEquals(new String[]{"0 0", "0 0"}, solver.makeSquare(2,1) );42 }43 @Test44 public void test7(){45 assertArrayEquals(new String[]{"0 1", "1 0"}, solver.makeSquare(2,2) );46 }47 @Test48 public void test8(){49 assertArrayEquals(new String[]{"0 0 1 2", "0 0 1 2", "1 1 2 0", "2 2 0 1"}, solver.makeSquare(4,3) );50 }51 @Test52 public void test9(){53 assertArrayEquals(new String[]{"0 1 2 3", "1 0 3 2", "2 3 0 1", "3 2 1 0"}, solver.makeSquare(4,4) );54 }55 @Test56 public void test10(){57 assertArrayEquals(new String[]{"0 0 0 1 2", "0 0 0 1 2", "0 0 0 1 2", "1 1 1 2 0", "2 2 2 0 1"}, solver.makeSquare(5,3) );58 }59 @Test60 public void test11(){61 assertArrayEquals(new String[]{"0 1 2 3 4", "1 0 3 4 2", "2 3 4 0 1", "3 4 1 2 0", "4 2 0 1 3"}, solver.makeSquare(5,5) );62 }63 @Test64 public void test12(){65 assertArrayEquals(new String[]{"0 0 0 1 2 3", "0 0 0 1 2 3", "0 0 0 1 2 3", "1 1 1 0 3 2", "2 2 2 3 0 1", "3 3 3 2 1 0"}, solver.makeSquare(6,4) );66 }67 @Test68 public void test13(){69 assertArrayEquals(new String[]{"0 1 2 3 4 5", "1 0 3 2 5 4", "2 3 4 5 0 1", "3 2 5 4 1 0", "4 5 0 1 2 3", "5 4 1 0 3 2"}, solver.makeSquare(6,6) );70 }71 @Test72 public void test14(){73 assertArrayEquals(new String[]{"0 0 0 0 0 0 0", "0 0 0 0 0 0 0", "0 0 0 0 0 0 0", "0 0 0 0 0 0 0", "0 0 0 0 0 0 0", "0 0 0 0 0 0 0", "0 0 0 0 0 0 0"}, solver.makeSquare(7,1) );74 }75 @Test76 public void test15(){77 assertArrayEquals(new String[]{"0 0 0 1 2 3 4", "0 0 0 1 2 3 4", "0 0 0 1 2 3 4", "1 1 1 0 3 4 2", "2 2 2 3 4 0 1", "3 3 3 4 1 2 0", "4 4 4 2 0 1 3"}, solver.makeSquare(7,5) );78 }79 @Test80 public void test16(){81 assertArrayEquals(new String[]{"0 0 1 2 3 4 5", "0 0 1 2 3 4 5", "1 1 0 3 2 5 4", "2 2 3 4 5 0 1", "3 3 2 5 4 1 0", "4 4 5 0 1 2 3", "5 5 4 1 0 3 2"}, solver.makeSquare(7,6) );82 }83 @Test84 public void test17(){85 assertArrayEquals(new String[]{"0 1 2 3 4 5 6", "1 0 3 2 5 6 4", "2 3 0 1 6 4 5", "3 4 5 6 0 1 2", "4 2 6 5 1 0 3", "5 6 1 4 2 3 0", "6 5 4 0 3 2 1"}, solver.makeSquare(7,7) );86 }87 @Test88 public void test18(){89 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 1", "1 1 1 1 1 1 1 0"}, solver.makeSquare(8,2) );90 }91 @Test92 public void test19(){93 assertArrayEquals(new String[]{"0 0 0 0 1 2 3 4", "0 0 0 0 1 2 3 4", "0 0 0 0 1 2 3 4", "0 0 0 0 1 2 3 4", "1 1 1 1 0 3 4 2", "2 2 2 2 3 4 0 1", "3 3 3 3 4 1 2 0", "4 4 4 4 2 0 1 3"}, solver.makeSquare(8,5) );94 }95 @Test96 public void test20(){97 assertArrayEquals(new String[]{"0 0 0 1 2 3 4 5", "0 0 0 1 2 3 4 5", "0 0 0 1 2 3 4 5", "1 1 1 0 3 2 5 4", "2 2 2 3 4 5 0 1", "3 3 3 2 5 4 1 0", "4 4 4 5 0 1 2 3", "5 5 5 4 1 0 3 2"}, solver.makeSquare(8,6) );98 }99 @Test100 public void test21(){101 assertArrayEquals(new String[]{"0 0 1 2 3 4 5 6", "0 0 1 2 3 4 5 6", "1 1 0 3 2 5 6 4", "2 2 3 0 1 6 4 5", "3 3 4 5 6 0 1 2", "4 4 2 6 5 1 0 3", "5 5 6 1 4 2 3 0", "6 6 5 4 0 3 2 1"}, solver.makeSquare(8,7) );102 }103 @Test104 public void test22(){105 assertArrayEquals(new String[]{"0 1 2 3 4 5 6 7", "1 0 3 2 5 4 7 6", "2 3 0 1 6 7 4 5", "3 2 1 0 7 6 5 4", "4 5 6 7 0 1 2 3", "5 4 7 6 1 0 3 2", "6 7 4 5 2 3 0 1", "7 6 5 4 3 2 1 0"}, solver.makeSquare(8,8) );106 }107 @Test108 public void test23(){109 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 1 2", "1 1 1 1 1 1 1 2 0", "2 2 2 2 2 2 2 0 1"}, solver.makeSquare(9,3) );110 }111 @Test112 public void test24(){113 assertArrayEquals(new String[]{"0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 1 2 3", "1 1 1 1 1 1 0 3 2", "2 2 2 2 2 2 3 0 1", "3 3 3 3 3 3 2 1 0"}, solver.makeSquare(9,4) );114 }115 @Test116 public void test25(){117 assertArrayEquals(new String[]{"0 0 0 0 0 1 2 3 4", "0 0 0 0 0 1 2 3 4", "0 0 0 0 0 1 2 3 4", "0 0 0 0 0 1 2 3 4", "0 0 0 0 0 1 2 3 4", "1 1 1 1 1 0 3 4 2", "2 2 2 2 2 3 4 0 1", "3 3 3 3 3 4 1 2 0", "4 4 4 4 4 2 0 1 3"}, solver.makeSquare(9,5) );118 }119 @Test120 public void test26(){121 assertArrayEquals(new String[]{"0 0 0 0 1 2 3 4 5", "0 0 0 0 1 2 3 4 5", "0 0 0 0 1 2 3 4 5", "0 0 0 0 1 2 3 4 5", "1 1 1 1 0 3 2 5 4", "2 2 2 2 3 4 5 0 1", "3 3 3 3 2 5 4 1 0", "4 4 4 4 5 0 1 2 3", "5 5 5 5 4 1 0 3 2"}, solver.makeSquare(9,6) );122 }123 @Test124 public void test27(){125 assertArrayEquals(new String[]{"0 0 0 1 2 3 4 5 6 7", "0 0 0 1 2 3 4 5 6 7", "0 0 0 1 2 3 4 5 6 7", "1 1 1 0 3 2 5 4 7 6", "2 2 2 3 0 1 6 7 4 5", "3 3 3 2 1 0 7 6 5 4", "4 4 4 5 6 7 0 1 2 3", "5 5 5 4 7 6 1 0 3 2", "6 6 6 7 4 5 2 3 0 1", "7 7 7 6 5 4 3 2 1 0"}, solver.makeSquare(10,8) );126 }127 @Test128 public void test28(){129 assertArrayEquals(new String[]{"0 0 1 2 3 4 5 6 7", "0 0 1 2 3 4 5 6 7", "1 1 0 3 2 5 4 7 6", "2 2 3 0 1 6 7 4 5", "3 3 2 1 0 7 6 5 4", "4 4 5 6 7 0 1 2 3", "5 5 4 7 6 1 0 3 2", "6 6 7 4 5 2 3 0 1", "7 7 6 5 4 3 2 1 0"}, solver.makeSquare(9,8) );130 }131 @Test132 public void test29(){133 assertArrayEquals(new String[]{"0 1 2 3 4 5 6 7 8", "1 0 3 2 5 4 7 8 6", "2 3 0 1 6 7 8 4 5", "3 2 1 0 7 8 5 6 4", "4 5 6 7 8 0 1 2 3", "5 4 7 8 0 6 2 3 1", "6 7 8 4 1 2 3 5 0", "7 8 5 6 3 1 4 0 2", "8 6 4 5 2 3 0 1 7"}, solver.makeSquare(9,9) );134 }135 @Test136 public void test30(){137 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0"}, solver.makeSquare(10,1) );138 }139 @Test140 public void test31(){141 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 0 1", "1 1 1 1 1 1 1 1 1 0"}, solver.makeSquare(10,2) );142 }143 @Test144 public void test32(){145 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "0 0 0 0 0 0 0 0 1 2", "1 1 1 1 1 1 1 1 2 0", "2 2 2 2 2 2 2 2 0 1"}, solver.makeSquare(10,3) );146 }147 @Test148 public void test33(){149 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 0 1 2 3", "0 0 0 0 0 0 0 1 2 3", "1 1 1 1 1 1 1 0 3 2", "2 2 2 2 2 2 2 3 0 1", "3 3 3 3 3 3 3 2 1 0"}, solver.makeSquare(10,4) );150 }151 @Test152 public void test34(){153 assertArrayEquals(new String[]{"0 0 0 0 0 0 1 2 3 4", "0 0 0 0 0 0 1 2 3 4", "0 0 0 0 0 0 1 2 3 4", "0 0 0 0 0 0 1 2 3 4", "0 0 0 0 0 0 1 2 3 4", "0 0 0 0 0 0 1 2 3 4", "1 1 1 1 1 1 0 3 4 2", "2 2 2 2 2 2 3 4 0 1", "3 3 3 3 3 3 4 1 2 0", "4 4 4 4 4 4 2 0 1 3"}, solver.makeSquare(10,5) );154 }155 @Test156 public void test35(){157 assertArrayEquals(new String[]{"0 0 0 0 0 1 2 3 4 5", "0 0 0 0 0 1 2 3 4 5", "0 0 0 0 0 1 2 3 4 5", "0 0 0 0 0 1 2 3 4 5", "0 0 0 0 0 1 2 3 4 5", "1 1 1 1 1 0 3 2 5 4", "2 2 2 2 2 3 4 5 0 1", "3 3 3 3 3 2 5 4 1 0", "4 4 4 4 4 5 0 1 2 3", "5 5 5 5 5 4 1 0 3 2"}, solver.makeSquare(10,6) );158 }159 @Test160 public void test36(){161 assertArrayEquals(new String[]{"0 0 0 0 1 2 3 4 5 6", "0 0 0 0 1 2 3 4 5 6", "0 0 0 0 1 2 3 4 5 6", "0 0 0 0 1 2 3 4 5 6", "1 1 1 1 0 3 2 5 6 4", "2 2 2 2 3 0 1 6 4 5", "3 3 3 3 4 5 6 0 1 2", "4 4 4 4 2 6 5 1 0 3", "5 5 5 5 6 1 4 2 3 0", "6 6 6 6 5 4 0 3 2 1"}, solver.makeSquare(10,7) );162 }163 @Test164 public void test37(){165 assertArrayEquals(new String[]{"0 0 1 2 3 4 5 6 7 8", "0 0 1 2 3 4 5 6 7 8", "1 1 0 3 2 5 4 7 8 6", "2 2 3 0 1 6 7 8 4 5", "3 3 2 1 0 7 8 5 6 4", "4 4 5 6 7 8 0 1 2 3", "5 5 4 7 8 0 6 2 3 1", "6 6 7 8 4 1 2 3 5 0", "7 7 8 5 6 3 1 4 0 2", "8 8 6 4 5 2 3 0 1 7"}, solver.makeSquare(10,9) );166 }167 @Test168 public void test38(){169 assertArrayEquals(new String[]{"0 0 0", "0 0 0", "0 0 0"}, solver.makeSquare(3,1) );170 }171 @Test172 public void test39(){173 assertArrayEquals(new String[]{"0 0 1", "0 0 1", "1 1 0"}, solver.makeSquare(3,2) );174 }175 @Test176 public void test40(){177 assertArrayEquals(new String[]{"0 0 0 0", "0 0 0 0", "0 0 0 0", "0 0 0 0"}, solver.makeSquare(4,1) );178 }179 @Test180 public void test41(){181 assertArrayEquals(new String[]{"0 0 0 1", "0 0 0 1", "0 0 0 1", "1 1 1 0"}, solver.makeSquare(4,2) );182 }183 @Test184 public void test42(){185 assertArrayEquals(new String[]{"0 0 0 0 0", "0 0 0 0 0", "0 0 0 0 0", "0 0 0 0 0", "0 0 0 0 0"}, solver.makeSquare(5,1) );186 }187 @Test188 public void test43(){189 assertArrayEquals(new String[]{"0 0 0 0 0 0", "0 0 0 0 0 0", "0 0 0 0 0 0", "0 0 0 0 0 0", "0 0 0 0 0 0", "0 0 0 0 0 0"}, solver.makeSquare(6,1) );190 }191 @Test192 public void test44(){193 assertArrayEquals(new String[]{"0 0 0 0 0 1", "0 0 0 0 0 1", "0 0 0 0 0 1", "0 0 0 0 0 1", "0 0 0 0 0 1", "1 1 1 1 1 0"}, solver.makeSquare(6,2) );194 }195 @Test196 public void test45(){197 assertArrayEquals(new String[]{"0 0 0 0 1 2", "0 0 0 0 1 2", "0 0 0 0 1 2", "0 0 0 0 1 2", "1 1 1 1 2 0", "2 2 2 2 0 1"}, solver.makeSquare(6,3) );198 }199 @Test200 public void test46(){201 assertArrayEquals(new String[]{"0 0 1 2 3 4", "0 0 1 2 3 4", "1 1 0 3 4 2", "2 2 3 4 0 1", "3 3 4 1 2 0", "4 4 2 0 1 3"}, solver.makeSquare(6,5) );202 }203 @Test204 public void test47(){205 assertArrayEquals(new String[]{"0 0 0 0 0 0 1", "0 0 0 0 0 0 1", "0 0 0 0 0 0 1", "0 0 0 0 0 0 1", "0 0 0 0 0 0 1", "0 0 0 0 0 0 1", "1 1 1 1 1 1 0"}, solver.makeSquare(7,2) );206 }207 @Test208 public void test48(){209 assertArrayEquals(new String[]{"0 0 0 0 0 1 2", "0 0 0 0 0 1 2", "0 0 0 0 0 1 2", "0 0 0 0 0 1 2", "0 0 0 0 0 1 2", "1 1 1 1 1 2 0", "2 2 2 2 2 0 1"}, solver.makeSquare(7,3) );210 }211 @Test212 public void test49(){213 assertArrayEquals(new String[]{"0 0 0 0 1 2 3", "0 0 0 0 1 2 3", "0 0 0 0 1 2 3", "0 0 0 0 1 2 3", "1 1 1 1 0 3 2", "2 2 2 2 3 0 1", "3 3 3 3 2 1 0"}, solver.makeSquare(7,4) );214 }215 @Test216 public void test50(){217 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0"}, solver.makeSquare(8,1) );218 }219 @Test220 public void test51(){221 assertArrayEquals(new String[]{"0 0 0 0 0 0 1 2", "0 0 0 0 0 0 1 2", "0 0 0 0 0 0 1 2", "0 0 0 0 0 0 1 2", "0 0 0 0 0 0 1 2", "0 0 0 0 0 0 1 2", "1 1 1 1 1 1 2 0", "2 2 2 2 2 2 0 1"}, solver.makeSquare(8,3) );222 }223 @Test224 public void test52(){225 assertArrayEquals(new String[]{"0 0 0 0 0 1 2 3", "0 0 0 0 0 1 2 3", "0 0 0 0 0 1 2 3", "0 0 0 0 0 1 2 3", "0 0 0 0 0 1 2 3", "1 1 1 1 1 0 3 2", "2 2 2 2 2 3 0 1", "3 3 3 3 3 2 1 0"}, solver.makeSquare(8,4) );226 }227 @Test228 public void test53(){229 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0"}, solver.makeSquare(9,1) );230 }231 @Test232 public void test54(){233 assertArrayEquals(new String[]{"0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "0 0 0 0 0 0 0 0 1", "1 1 1 1 1 1 1 1 0"}, solver.makeSquare(9,2) );234 }235}...

Full Screen

Full Screen

Source:BaseNd4jTest.java Github

copy

Full Screen

...79 if (backend.canRun() && backendsToRun.contains(backend.getClass().getName()) || backendsToRun.isEmpty())80 backends.add(backend);81 }82 }83 public static void assertArrayEquals(String string, Object[] expecteds, Object[] actuals) {84 org.junit.Assert.assertArrayEquals(string, expecteds, actuals);85 }86 public static void assertArrayEquals(Object[] expecteds, Object[] actuals) {87 org.junit.Assert.assertArrayEquals(expecteds, actuals);88 }89 public static void assertArrayEquals(String string, long[] shapeA, long[] shapeB) {90 org.junit.Assert.assertArrayEquals(string, shapeA, shapeB);91 }92 public static void assertArrayEquals(String string, byte[] shapeA, byte[] shapeB) {93 org.junit.Assert.assertArrayEquals(string, shapeA, shapeB);94 }95 public static void assertArrayEquals(byte[] shapeA, byte[] shapeB) {96 org.junit.Assert.assertArrayEquals(shapeA, shapeB);97 }98 public static void assertArrayEquals(long[] shapeA, long[] shapeB) {99 org.junit.Assert.assertArrayEquals(shapeA, shapeB);100 }101 public static void assertArrayEquals(String string, int[] shapeA, long[] shapeB) {102 org.junit.Assert.assertArrayEquals(string, ArrayUtil.toLongArray(shapeA), shapeB);103 }104 public static void assertArrayEquals(int[] shapeA, long[] shapeB) {105 org.junit.Assert.assertArrayEquals(ArrayUtil.toLongArray(shapeA), shapeB);106 }107 public static void assertArrayEquals(String string, long[] shapeA, int[] shapeB) {108 org.junit.Assert.assertArrayEquals(string, shapeA, ArrayUtil.toLongArray(shapeB));109 }110 public static void assertArrayEquals(long[] shapeA, int[] shapeB) {111 org.junit.Assert.assertArrayEquals(shapeA, ArrayUtil.toLongArray(shapeB));112 }113 public static void assertArrayEquals(String string, int[] shapeA, int[] shapeB) {114 org.junit.Assert.assertArrayEquals(string, shapeA, shapeB);115 }116 public static void assertArrayEquals(int[] shapeA, int[] shapeB) {117 org.junit.Assert.assertArrayEquals(shapeA, shapeB);118 }119 public static void assertArrayEquals(String string, boolean[] shapeA, boolean[] shapeB) {120 org.junit.Assert.assertArrayEquals(string, shapeA, shapeB);121 }122 public static void assertArrayEquals(boolean[] shapeA, boolean[] shapeB) {123 org.junit.Assert.assertArrayEquals(shapeA, shapeB);124 }125 public static void assertArrayEquals(float[] shapeA, float[] shapeB, float delta) {126 org.junit.Assert.assertArrayEquals(shapeA, shapeB, delta);127 }128 public static void assertArrayEquals(double[] shapeA, double[] shapeB, double delta) {129 org.junit.Assert.assertArrayEquals(shapeA, shapeB, delta);130 }131 public static void assertArrayEquals(String string, float[] shapeA, float[] shapeB, float delta) {132 org.junit.Assert.assertArrayEquals(string, shapeA, shapeB, delta);133 }134 public static void assertArrayEquals(String string, double[] shapeA, double[] shapeB, double delta) {135 org.junit.Assert.assertArrayEquals(string, shapeA, shapeB, delta);136 }137 @Parameterized.Parameters(name = "{index}: backend({0})={1}")138 public static Collection<Object[]> configs() {139 List<Object[]> ret = new ArrayList<>();140 for (Nd4jBackend backend : backends)141 ret.add(new Object[] {backend});142 return ret;143 }144 /**145 * Get the default backend (jblas)146 * The default backend can be overridden by also passing:147 * -Dorg.nd4j.linalg.defaultbackend=your.backend.classname148 * @return the default backend based on the149 * given command line arguments...

Full Screen

Full Screen

Source:FSFindDocumentTests.java Github

copy

Full Screen

1package com.shtrih.fiscalprinter.command;2import org.junit.Test;3import static com.shtrih.util.ByteUtils.byteArray;4import static org.junit.Assert.assertArrayEquals;5import static org.junit.Assert.assertEquals;6import static org.junit.Assert.assertArrayEquals;7import static org.junit.Assert.assertEquals;8import static org.junit.Assert.assertArrayEquals;9import static org.junit.Assert.assertEquals;10import static org.junit.Assert.assertArrayEquals;11import static org.junit.Assert.assertEquals;12import static org.junit.Assert.assertArrayEquals;13import static org.junit.Assert.assertEquals;14import static org.junit.Assert.assertArrayEquals;15import static org.junit.Assert.assertEquals;16import static org.junit.Assert.assertArrayEquals;17import static org.junit.Assert.assertEquals;18import static org.junit.Assert.assertArrayEquals;19import static org.junit.Assert.assertEquals;20import static org.junit.Assert.assertArrayEquals;21import static org.junit.Assert.assertEquals;22import static org.junit.Assert.assertArrayEquals;23import static org.junit.Assert.assertEquals;24import static org.junit.Assert.assertArrayEquals;25import static org.junit.Assert.assertEquals;26import static org.junit.Assert.assertArrayEquals;27import static org.junit.Assert.assertEquals;28import static org.junit.Assert.assertArrayEquals;29import static org.junit.Assert.assertEquals;30import static org.junit.Assert.assertArrayEquals;31import static org.junit.Assert.assertEquals;32import static org.junit.Assert.assertArrayEquals;33import static org.junit.Assert.assertEquals;34import static org.junit.Assert.assertArrayEquals;35import static org.junit.Assert.assertEquals;36/**37 * @author P.Zhirkov38 */39public class FSFindDocumentTests {40 @Test41 public void should_serialize_request() throws Exception {42 FSFindDocument cmd = new FSFindDocument(30, 163);43 byte[] data = cmd.encodeData();44 byte[] expectedData = byteArray(0xFF, 0x0A, 0x1E, 0x00, 0x00, 0x00, 0xA3, 0x00, 0x00, 0x00);45 assertArrayEquals(expectedData, data);46 }47 @Test48 public void should_deserialize_check() throws Exception {49 FSFindDocument cmd = new FSFindDocument(30, 163);50 byte[] responseData = byteArray(51 0xFF, 0x0A,52 0x00, 0x03, 0x00,53 0x11, 0x03, 0x18, 0x14, 0x35, 0xA3, 0x00, 0x00, 0x00, 0xEB,54 0xEA, 0x4B, 0x2E, 0x01, 0x20, 0x4E, 0x00, 0x00, 0x0055 );56 cmd.decodeData(responseData);57 FSDocument document = cmd.getDocument();58 assertEquals(3, document.getDocType());59 assertEquals(false, document.isTicketReceived());60 assertArrayEquals(byteArray(61 0x01, 0x20, 0x4E, 0x00, 0x00, 0x0062 ), document.getData());63 assertEquals(2017, document.getDateTime().getYear());64 assertEquals(3, document.getDateTime().getMonth());65 assertEquals(24, document.getDateTime().getDay());66 assertEquals(20, document.getDateTime().getHours());67 assertEquals(53, document.getDateTime().getMinutes());68 assertEquals(0xA3, document.getDocNumber());69 assertEquals(0x2E4BEAEBL, document.getDocSign());70 }71 @Test72 public void should_deserialize_fiscalization() throws Exception {73 FSFindDocument cmd = new FSFindDocument(30, 163);74 byte[] responseData = byteArray(75 0xFF, 0x0A, 0x00, 0x01, 0x00, 0x11, 0x07, 0x06, 0x02, 0x34,76 0x01, 0x00, 0x00, 0x00, 0xB7, 0x9F, 0xD1, 0x4D, 0x35, 0x30,77 0x32, 0x34, 0x30, 0x35, 0x34, 0x34, 0x34, 0x35, 0x20, 0x20,78 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x33, 0x35, 0x38,79 0x30, 0x32, 0x36, 0x31, 0x33, 0x31, 0x20, 0x20, 0x20, 0x20,80 0x3F, 0x0181 );82 cmd.decodeData(responseData);83 FSDocument document = cmd.getDocument();84 assertEquals(1, document.getDocType());85 assertEquals(false, document.isTicketReceived());86 assertArrayEquals(byteArray(87 0x35, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x34, 0x34, 0x35,88 0x20, 0x20, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x33,89 0x35, 0x38, 0x30, 0x32, 0x36, 0x31, 0x33, 0x31, 0x20, 0x20,90 0x20, 0x20, 0x3F, 0x0191 ), document.getData());92 assertEquals(2017, document.getDateTime().getYear());93 assertEquals(7, document.getDateTime().getMonth());94 assertEquals(6, document.getDateTime().getDay());95 assertEquals(2, document.getDateTime().getHours());96 assertEquals(52, document.getDateTime().getMinutes());97 assertEquals(1, document.getDocNumber());98 assertEquals(1305583543, document.getDocSign());99 }100 @Test101 public void should_deserialize_refiscalization() throws Exception {102 FSFindDocument cmd = new FSFindDocument(30, 163);103 byte[] responseData = byteArray(104 0xFF, 0x0A, 0x00, 0x0B, 0x00, 0x11, 0x07, 0x06, 0x02, 0x35,105 0x02, 0x00, 0x00, 0x00, 0x22, 0xE8, 0x9A, 0x18, 0x35, 0x30,106 0x32, 0x34, 0x30, 0x35, 0x34, 0x34, 0x34, 0x35, 0x20, 0x20,107 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x33, 0x35, 0x38,108 0x30, 0x32, 0x36, 0x31, 0x33, 0x31, 0x20, 0x20, 0x20, 0x20,109 0x3F, 0x01, 0x04110 );111 cmd.decodeData(responseData);112 FSDocument document = cmd.getDocument();113 assertEquals(11, document.getDocType());114 assertEquals(false, document.isTicketReceived());115 assertArrayEquals(byteArray(116 0x35, 0x30, 0x32, 0x34, 0x30, 0x35, 0x34, 0x34, 0x34, 0x35,117 0x20, 0x20, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x33,118 0x35, 0x38, 0x30, 0x32, 0x36, 0x31, 0x33, 0x31, 0x20, 0x20,119 0x20, 0x20, 0x3F, 0x01, 0x04120 ), document.getData());121 assertEquals(2017, document.getDateTime().getYear());122 assertEquals(7, document.getDateTime().getMonth());123 assertEquals(6, document.getDateTime().getDay());124 assertEquals(2, document.getDateTime().getHours());125 assertEquals(53, document.getDateTime().getMinutes());126 assertEquals(2, document.getDocNumber());127 assertEquals(412805154, document.getDocSign());128 }129 @Test130 public void should_deserialize_shift_open() throws Exception {131 FSFindDocument cmd = new FSFindDocument(30, 163);132 byte[] responseData = byteArray(133 0xFF, 0x0A, 0x00, 0x02, 0x00, 0x11, 0x07, 0x06, 0x02, 0x35,134 0x03, 0x00, 0x00, 0x00, 0x5B, 0xE1, 0xAE, 0xD0, 0x01, 0x00135 );136 cmd.decodeData(responseData);137 FSDocument document = cmd.getDocument();138 assertEquals(2, document.getDocType());139 assertEquals(false, document.isTicketReceived());140 assertArrayEquals(byteArray(141 0x01, 0x00142 ), document.getData());143 assertEquals(2017, document.getDateTime().getYear());144 assertEquals(7, document.getDateTime().getMonth());145 assertEquals(6, document.getDateTime().getDay());146 assertEquals(2, document.getDateTime().getHours());147 assertEquals(53, document.getDateTime().getMinutes());148 assertEquals(3, document.getDocNumber());149 assertEquals(3501121883L, document.getDocSign());150 }151 @Test152 public void should_deserialize_shift_close() throws Exception {153 FSFindDocument cmd = new FSFindDocument(30, 163);154 byte[] responseData = byteArray(155 0xFF, 0x0A, 0x00, 0x05, 0x00, 0x11, 0x07, 0x06, 0x02, 0x36,156 0x06, 0x00, 0x00, 0x00, 0xFD, 0x00, 0x61, 0xD9, 0x01, 0x00157 );158 cmd.decodeData(responseData);159 FSDocument document = cmd.getDocument();160 assertEquals(5, document.getDocType());161 assertEquals(false, document.isTicketReceived());162 assertArrayEquals(byteArray(163 0x01, 0x00164 ), document.getData());165 assertEquals(2017, document.getDateTime().getYear());166 assertEquals(7, document.getDateTime().getMonth());167 assertEquals(6, document.getDateTime().getDay());168 assertEquals(2, document.getDateTime().getHours());169 assertEquals(54, document.getDateTime().getMinutes());170 assertEquals(6, document.getDocNumber());171 assertEquals(3647013117L, document.getDocSign());172 }173}...

Full Screen

Full Screen

Source:GaussTest.java Github

copy

Full Screen

1import org.junit.*;2import static org.junit.Assert.assertEquals;3import static org.junit.Assert.assertTrue;4import static org.junit.Assert.assertArrayEquals;5import java.util.Arrays;6import java.util.Random;7public class GaussTest {8 @Test9 public void testGauss1(){10 //example111 double[][] matrix = {{3,-2},12 {5,1}};13 double[] rightSide = {-6, 3};14 double[] solution = {0,3};15 double[] result = Gauss.solve(matrix,rightSide);16 assertTrue(Arrays.equals(solution,result));17 }18 @Test19 public void testGauss2(){20 //example221 double[][] matrix =22 {{1, -1, 3, 1},23 {4, -1, 5, 4},24 {2, -2, 4, 1},25 {1, -4, 5, -1}};26 double[] rightSide = {5, 4, 6, 3};27 double[] solution = {9, 18, 10, -16};28 double[] result = Gauss.solve(matrix,rightSide);29 assertArrayEquals(solution, result, 0.001);30 }31 @Test32 public void testGauss3(){33 //example234 double[][] matrix =35 {{3, 2, -5},36 {2, -1, 3},37 {1, 2, -1}};38 double[] rightSide = {-1, 13, 9};39 double[] solution = {3, 5, 4};40 double[] result = Gauss.solve(matrix,rightSide);41 assertArrayEquals(solution, result, 0.001);42 }43 @Test44 public void testGauss4(){45 //example246 double[][] matrix =47 {{3, 1, -5},48 {2, -1, 3},49 {1, 2, -1}};50 double[] rightSide = {-1, 13, 9};51 double[] solution = {3.7, 4.3, 3.3};52 double[] result = Gauss.solve(matrix,rightSide);53 assertArrayEquals(solution, result, 0.1);54 }55 @Test56 public void testGauss5(){57 //example258 double[][] matrix =59 {{3, 2, -5},60 {2, -1, 1},61 {1, 2, -1}};62 double[] rightSide = {-1, 3, 9};63 double[] solution = {2.3, 5.2, 3.6};64 double[] result = Gauss.solve(matrix,rightSide);65 assertArrayEquals(solution, result, 0.1);66 }67 @Test68 public void testGauss6(){69 //example270 double[][] matrix =71 {{1, -1, 3, 1},72 {4, -1, 5, 4},73 {2, -2, 4, 1},74 {1, -4, -5, -1}};75 double[] rightSide = {5, 1, 4, 3};76 double[] solution = {-6.3, -4.4, 0.8, 4.4};77 double[] result = Gauss.solve(matrix,rightSide);78 assertArrayEquals(solution, result, 0.1);79 }80 @Test81 public void testGauss7(){82 //example283 double[][] matrix =84 {{1, -1, 3, 1},85 {1, -1, 69, 42},86 {2, -2, 228, 504},87 {1, -4, -666, -1}};88 double[] rightSide = {5, 1, 420, 3};89 double[] solution = {180.7, 174.5, -0.8, 1.2};90 double[] result = Gauss.solve(matrix,rightSide);91 assertArrayEquals(solution, result, 0.1);92 }93 @Test94 public void testGauss8(){95 //example296 double[][] matrix =97 {{24, 12, 1},98 {29, 8, 99},99 {17, 4, 1}};100 double[] rightSide = {-1, 13, 9};101 double[] solution = {1, -2.2, 0.001};102 double[] result = Gauss.solve(matrix,rightSide);103 assertArrayEquals(solution, result, 0.1);104 }105}...

Full Screen

Full Screen

Source:UtilidadesTest.java Github

copy

Full Screen

...28 @Test29 public void testOrdenar3Iguales() {30 for (int i = 0 ; i < n ; i++ ) {31 int n1 = (int)Math.random()*(max - min) + min + 1; 32 assertArrayEquals("3 números iguales", new int[]{ n1, n1, n1 } , Utilidades.ordenar( n1, n1, n1 ));33 }34 }35 @Test // Este test falla con el método Utilidades.ordenar comentado 36 public void testOrdenar2Iguales() {37 for (int i = 0 ; i < n ; i++ ) {38 int n1 = (int)Math.random()*(max - min) + min + 1;39 assertArrayEquals("2 números iguales", new int[]{ n1-3, n1, n1 } , Utilidades.ordenar( n1, n1, n1-3 ));40 }41 }42 @Test43 public void testOrdenarConsecutivos() {44 for (int i = 0 ; i < n ; i++ ) {45 int n1 = (int)Math.random()*(max - min) + min + 1; 46 assertArrayEquals("Números consecutivos", new int[]{ n1, n1+1, n1+2 } , Utilidades.ordenar( n1, n1+1, n1+2 ));47 }48 }49 @Test50 public void testOrdenarConsecutivosInverso() {51 for (int i = 0 ; i < n ; i++ ) {52 int n1 = (int)Math.random()*(max - min) + min + 1; 53 assertArrayEquals("Números consecutivos en orden inverso", new int[]{ n1-2, n1-1, n1 } , Utilidades.ordenar( n1, n1-1, n1-2 ));54 }55 }56 57 @Test // Este test falla con el método Utilidades.ordenar comentado 58 public void cobertura () {59 assertArrayEquals ("Caso 1, 2, 3", new int[]{1, 2, 3}, Utilidades.ordenar(1, 2, 3) );60 assertArrayEquals ("Caso 1, 3, 2", new int[]{1, 2, 3}, Utilidades.ordenar(1, 3, 2) );61 assertArrayEquals ("Caso 2, 1, 3", new int[]{1, 2, 3}, Utilidades.ordenar(2, 1, 3) );62 assertArrayEquals ("Caso 3, 2, 1", new int[]{1, 2, 3}, Utilidades.ordenar(3, 1, 2) ); 63 assertArrayEquals ("Caso 2, 3, 1", new int[]{1, 2, 3}, Utilidades.ordenar(2, 3, 1) );64 assertArrayEquals ("Caso 3, 2, 1", new int[]{1, 2, 3}, Utilidades.ordenar(3, 2, 1) );65 assertArrayEquals ("Caso 3, 1, 1", new int[]{1, 1, 3}, Utilidades.ordenar(3, 1, 1) ); // Este caso falla66 assertArrayEquals ("Caso 1, 1, 1", new int[]{1, 1, 1}, Utilidades.ordenar(1, 1, 1) ); 67 }68 69 @After70 public void tearDown(){71 // Aquí ponemos lo que deseamos ejecutar al finalizar cada test.72 // (Método vacío)73 }74 75}...

Full Screen

Full Screen

Source:CombinatorFactoryTest.java Github

copy

Full Screen

...5public class CombinatorFactoryTest {6 @Test7 public void combinator_3_2() {8 ICombinator combinator = rn.tool.combination.CombinatorFactory.create(3, 2);9 org.junit.Assert.assertArrayEquals(new int[] {0, 1}, combinator.next());10 org.junit.Assert.assertArrayEquals(new int[] {0, 2}, combinator.next());11 org.junit.Assert.assertArrayEquals(new int[] {0, 3}, combinator.next());12 org.junit.Assert.assertArrayEquals(new int[] {1, 2}, combinator.next());13 org.junit.Assert.assertArrayEquals(new int[] {1, 3}, combinator.next());14 org.junit.Assert.assertArrayEquals(new int[] {2, 3}, combinator.next());15 org.junit.Assert.assertNull(combinator.next());16 }17 @Test18 public void variant_length() {19 ICombinator combinator = rn.tool.combination.CombinatorFactory.variantLength(3);20 org.junit.Assert.assertArrayEquals(new int[] {0}, combinator.next());21 org.junit.Assert.assertArrayEquals(new int[] {1}, combinator.next());22 org.junit.Assert.assertArrayEquals(new int[] {2}, combinator.next());23 org.junit.Assert.assertArrayEquals(new int[] {3}, combinator.next());24 org.junit.Assert.assertArrayEquals(new int[] {0, 1}, combinator.next());25 org.junit.Assert.assertArrayEquals(new int[] {0, 2}, combinator.next());26 org.junit.Assert.assertArrayEquals(new int[] {0, 3}, combinator.next());27 org.junit.Assert.assertArrayEquals(new int[] {1, 2}, combinator.next());28 org.junit.Assert.assertArrayEquals(new int[] {1, 3}, combinator.next());29 org.junit.Assert.assertArrayEquals(new int[] {2, 3}, combinator.next());30 org.junit.Assert.assertArrayEquals(new int[] {0, 1, 2}, combinator.next());31 org.junit.Assert.assertArrayEquals(new int[] {0, 1, 3}, combinator.next());32 org.junit.Assert.assertArrayEquals(new int[] {0, 2, 3}, combinator.next());33 org.junit.Assert.assertArrayEquals(new int[] {1, 2, 3}, combinator.next());34 org.junit.Assert.assertArrayEquals(new int[] {0, 1, 2, 3}, combinator.next());35 org.junit.Assert.assertNull(combinator.next());36 }37}...

Full Screen

Full Screen

Source:CellTest.java Github

copy

Full Screen

...5 @org.junit.jupiter.api.Test6 void setCw() {7 test1.setCw(-1);8 test2.setCw(10);9 assertArrayEquals(-1,test1.getCl());10 assertArrayEquals(10,test2.getCl());11 }12 @org.junit.jupiter.api.Test13 void setCl() {14 test1.setCl(-1);15 test2.setCl(10);16 assertArrayEquals(-1,test1.getCl());17 assertArrayEquals(10,test2.getCl());18 }19 @org.junit.jupiter.api.Test20 void getCl() {21 assertArrayEquals(1,test1.getCl());22 }23 private void assertArrayEquals(int i, int cl) {24 }25 @org.junit.jupiter.api.Test26 void getCw() {27 assertArrayEquals(1,test1.getCw());28 assertArrayEquals(0,test2.getCw());29 }30 @org.junit.jupiter.api.Test31 void setAlive() {32 test1.setAlive(1);33 test2.setAlive(0);34 assertArrayEquals(1,test1.getIsAlive());35 assertArrayEquals(1,test2.getIsAlive());36 }37 @org.junit.jupiter.api.Test38 void getIsAlive() {39 assertArrayEquals(0,test1.getIsAlive());40 assertArrayEquals(0,test2.getIsAlive());41 }42}...

Full Screen

Full Screen

assertArrayEquals

Using AI Code Generation

copy

Full Screen

1import org.junit.Assert;2import org.junit.Test;3public class AssertArrayEqualsTest {4 public void testAssertArrayEquals() {5 byte[] expected = "trial".getBytes();6 byte[] actual = "trial".getBytes();7 Assert.assertArrayEquals("failure - byte arrays not same", expected, actual);8 }9}10package com.java2novice.junit;11import org.junit.Assert;12import org.junit.Test;13public class AssertArrayEqualsTest {14 public void testAssertArrayEquals() {15 String[] expected = new String[]{"one", "two", "three"};16 String[] actual = new String[]{"one", "two", "three"};17 Assert.assertArrayEquals("failure - string arrays are not same", expected, actual);18 }19}20package com.java2novice.junit;21import org.junit.Assert;22import org.junit.Test;23public class AssertArrayEqualsTest {24 public void testAssertArrayEquals() {25 String[] expected = new String[]{"one", "two", "three"};26 String[] actual = new String[]{"one", "two", "three"};27 Assert.assertArrayEquals("failure - string arrays are not same", expected, actual);28 }29}30package com.java2novice.junit;31import org.junit.Assert;32import org.junit.Test;33public class AssertArrayEqualsTest {34 public void testAssertArrayEquals() {35 String[] expected = new String[]{"one", "two", "three"};

Full Screen

Full Screen

assertArrayEquals

Using AI Code Generation

copy

Full Screen

1import org.junit.Assert;2import org.junit.Test;3public class AssertArrayEqualsTest {4 public void testAssertArrayEquals() {5 byte[] expected = "trial".getBytes();6 byte[] actual = "trial".getBytes();7 Assert.assertArrayEquals("failure - byte arrays not same", expected, actual);8 }9}10 at org.junit.Assert.assertEquals(Assert.java:115)11 at org.junit.Assert.assertEquals(Assert.java:144)12 at org.junit.Assert.assertArrayEquals(Assert.java:455)13 at org.junit.Assert.assertArrayEquals(Assert.java:468)14 at AssertArrayEqualsTest.testAssertArrayEquals(AssertArrayEqualsTest.java:10)15assertArrayEquals(String message, byte[] expecteds, byte[] actuals)16assertArrayEquals(String message, char[] expecteds, char[] actuals)17assertArrayEquals(String message, short[] expecteds, short[] actuals)18assertArrayEquals(String message, int[] expecteds, int[] actuals)19assertArrayEquals(String message, long[] expecteds, long[] actuals)20assertArrayEquals(String message, float[] expecteds, float[] actuals)21assertArrayEquals(String message, double[] expecteds, double[] actuals)22assertArrayEquals(String message, Object[] expecteds, Object[] actuals)23assertArrayEquals(String message, boolean[] expecteds, boolean[] actuals)24assertArrayEquals(String message, byte[] expecteds, byte[] actuals, int length)25assertArrayEquals(String message, char[] expecteds, char[] actuals, int length)26assertArrayEquals(String message, short[] expecteds, short[] actuals, int length)27assertArrayEquals(String message, int[] expecteds, int[] actuals, int length)28assertArrayEquals(String message, long[] expecteds, long[] actuals, int length)29assertArrayEquals(String message, float[] expecteds, float[] actuals, int length)30assertArrayEquals(String message, double[] expecteds, double[] actuals, int length)31assertArrayEquals(String message, Object[] expecteds, Object[] actuals, int length)

Full Screen

Full Screen

assertArrayEquals

Using AI Code Generation

copy

Full Screen

1import java.util.Arrays;2import org.junit.Assert;3import org.junit.Test;4public class AssertArrayEqualsExample {5 public void testAssertArrayEquals() {6 byte[] expected = "trial".getBytes();7 byte[] actual = "trial".getBytes();8 Assert.assertArrayEquals("failure - byte arrays not same", expected, actual);9 }10 public void testAssertArrayEqualsWithMessage() {11 byte[] expected = "trial".getBytes();12 byte[] actual = "trial".getBytes();13 Assert.assertArrayEquals("failure - byte arrays not same", expected, actual);14 }15 public void testAssertArrayEqualsWithDelta() {16 double[] expected = new double[] { 1.0, 2.0, 3.0 };17 double[] actual = new double[] { 1.0, 2.0, 3.0 };18 double delta = 0.01;19 Assert.assertArrayEquals("failure - double arrays not same", expected, actual, delta);20 }21 public void testAssertArrayEqualsWithDeltaAndMessage() {22 double[] expected = new double[] { 1.0, 2.0, 3.0 };23 double[] actual = new double[] { 1.0, 2.0, 3.0 };24 double delta = 0.01;25 Assert.assertArrayEquals("failure - double arrays not same", expected, actual, delta);26 }27 public void testAssertArrayEqualsWithDeltaAndMessage2() {28 double[] expected = new double[] { 1.0, 2.0, 3.0 };29 double[] actual = new double[] { 1.0, 2.01, 3.0 };30 double delta = 0.01;31 Assert.assertArrayEquals("failure - double arrays not same", expected, actual, delta);32 }33 public void testAssertArrayEqualsWithDeltaAndMessage3() {34 double[] expected = new double[] { 1.0, 2.0, 3.0 };35 double[] actual = new double[] { 1.0, 2.01, 3.0 };36 double delta = 0.001;37 Assert.assertArrayEquals("failure - double arrays not

Full Screen

Full Screen

assertArrayEquals

Using AI Code Generation

copy

Full Screen

1import static org.junit.Assert.assertArrayEquals;2import org.junit.Test;3public class ArrayEqualsTest {4 public void testArrayEquals() {5 byte[] expected = "trial".getBytes();6 byte[] actual = "trial".getBytes();7 assertArrayEquals("failure - byte arrays not same", expected, actual);8 }9}10 at org.junit.Assert.assertEquals(Assert.java:115)11 at org.junit.Assert.assertEquals(Assert.java:144)12 at org.junit.Assert.assertArrayEquals(Assert.java:418)13 at org.junit.Assert.assertArrayEquals(Assert.java:429)14 at ArrayEqualsTest.testArrayEquals(ArrayEqualsTest.java:13)15assertArrayEquals() method is overloaded and can be used to compare arrays of type:16Example 2: Using assertArrayEquals() method to compare arrays of type boolean[], byte[], char[], int[], long[], float[], double[], Object[] and String[]17package com.journaldev.junit;18import static org.junit.Assert.assertArrayEquals;19import org.junit.Test;20public class ArrayEqualsTest {21 public void testArrayEquals() {22 boolean[] expected = { true, false, true };23 boolean[] actual = { true, false, true };24 assertArrayEquals("failure - boolean arrays not same", expected, actual);25 }26 public void testArrayEquals2() {27 byte[] expected = { 1, 2, 3 };28 byte[] actual = { 1, 2, 3 };29 assertArrayEquals("failure - byte arrays not same", expected, actual);30 }31 public void testArrayEquals3() {32 char[] expected = {

Full Screen

Full Screen

assertArrayEquals

Using AI Code Generation

copy

Full Screen

1import org.junit.Assert;2public class ArrayEqualsTest {3 public void testArrayEquals() {4 int[] a = {1, 2, 3, 4, 5};5 int[] b = {1, 2, 3, 4, 5};6 int[] c = {1, 2, 3, 4, 6};7 Assert.assertArrayEquals(a, b);8 Assert.assertArrayEquals(b, c);9 }10}11 at org.junit.Assert.assertEquals(Assert.java:115)12 at org.junit.Assert.assertEquals(Assert.java:144)13 at org.junit.Assert.assertArrayEquals(Assert.java:347)14 at org.junit.Assert.assertArrayEquals(Assert.java:358)15 at com.journaldev.junit.ArrayEqualsTest.testArrayEquals(ArrayEqualsTest.java:11)16assertArrayEquals() method is overloaded, it has following signatures:17public static void assertArrayEquals(String message, Object[] expecteds, Object[] actuals)18public static void assertArrayEquals(Object[] expecteds, Object[] actuals)19public static void assertArrayEquals(String message, boolean[] expecteds, boolean[] actuals)20public static void assertArrayEquals(boolean[] expecteds, boolean[] actuals)21public static void assertArrayEquals(String message, byte[] expecteds, byte[] actuals)22public static void assertArrayEquals(byte[] expecteds, byte[] actuals)23public static void assertArrayEquals(String message, char[] expecteds, char[] actuals)24public static void assertArrayEquals(char[] expecteds, char[] actuals)25public static void assertArrayEquals(String message, short[] expecteds, short[] actuals)26public static void assertArrayEquals(short[] expecteds, short[] actuals)27public static void assertArrayEquals(String message, int[] expecteds, int[] actuals)28public static void assertArrayEquals(int[] expecteds, int[] actuals)29public static void assertArrayEquals(String message, long[] expecteds, long[] actuals)30public static void assertArrayEquals(long[] expecteds, long[] actuals)

Full Screen

Full Screen

assertArrayEquals

Using AI Code Generation

copy

Full Screen

1import org.junit.Assert;2import org.junit.Test;3public class MultidimensionalArrayAssertEqualsTest {4 public void testAssertArrayEquals() {5 byte[][] expected = {{1, 2}, {3, 4}};6 byte[][] actual = {{1, 2}, {3, 4}};7 Assert.assertArrayEquals(expected, actual);8 }9}10byte arrays differed at element [1][0]; expected:<3> but was:<0>11at org.junit.Assert.fail(Assert.java:88)12at org.junit.Assert.failNotEquals(Assert.java:743)13at org.junit.Assert.assertArrayEquals(Assert.java:458)14at org.junit.Assert.assertArrayEquals(Assert.java:467)15at com.journaldev.junit.MultidimensionalArrayAssertEqualsTest.testAssertArrayEquals(MultidimensionalArrayAssertEqualsTest.java:15)16at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)17at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)18at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)19at java.lang.reflect.Method.invoke(Method.java:606)20at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)21at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)22at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)23at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)24at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)25at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)26at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)27at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)28at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)29at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)30at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)31at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)32at org.junit.runners.ParentRunner.run(ParentRunner.java:363)33at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

Full Screen

Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful