Ejemplo n.º 1
0
 @Test
 public void testGetVelocity() throws Exception {
   assertNotSame(VELOCITY, moveRequest1.getVelocity());
   assertNotSame(VELOCITY, moveRequest2.getVelocity());
   assertArrayEquals(VELOCITY, moveRequest1.getVelocity(), 0.00001);
   assertArrayEquals(VELOCITY, moveRequest2.getVelocity(), 0.00001);
 }
Ejemplo n.º 2
0
 /** Test of fillFromVector method, of class Vector. */
 @Test
 public void testFillFromVector() {
   System.out.println("fillFromVector");
   // Arrange
   double[] mass0 = {0.0, 0.9, -6.4, 8, -0.4};
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] mass2 = {5.0, -2.9, 0.0};
   double[] mass3 = {5.0, -2.9, 0.0, -50000, 9, 0.6};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass0);
   VectorImpl vector = new VectorImpl(5);
   vector.setData(mass);
   VectorImpl instance2 = new VectorImpl(5);
   instance2.setData(mass0);
   VectorImpl vector2 = new VectorImpl(3);
   vector2.setData(mass2);
   VectorImpl instance3 = new VectorImpl(5);
   instance3.setData(mass0);
   VectorImpl vector3 = new VectorImpl(6);
   vector3.setData(mass3);
   // Act
   instance.fillFromVector(vector);
   instance2.fillFromVector(vector2);
   instance3.fillFromVector(vector3);
   // Assert
   assertArrayEquals(mass, instance.getData(), 0.0);
   assertArrayEquals(mass2, instance2.getData(), 0.0);
   assertArrayEquals(mass3, instance3.getData(), 0.0);
 }
Ejemplo n.º 3
0
 /** Test of deleteElement method, of class Vector. */
 @Test
 public void testDeleteElement() {
   System.out.println("deleteElement");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] mass1 = {5.0, -2.9, 0.0, -50000};
   double[] mass2 = {5.0, -2.9, -50000, 9};
   double[] mass3 = {-2.9, 0.0, -50000, 9};
   int index1 = 4;
   int index2 = 2;
   int index3 = 0;
   VectorImpl instance1 = new VectorImpl(5);
   instance1.setData(mass);
   VectorImpl instance2 = new VectorImpl(5);
   instance2.setData(mass);
   VectorImpl instance3 = new VectorImpl(5);
   instance3.setData(mass);
   // Act
   instance1.deleteElement(index1);
   instance2.deleteElement(index2);
   instance3.deleteElement(index3);
   // Assert
   assertArrayEquals(mass1, instance1.getData(), 0.0);
   assertArrayEquals(mass2, instance2.getData(), 0.0);
   assertArrayEquals(mass3, instance3.getData(), 0.0);
 }
Ejemplo n.º 4
0
 @Test
 // The following test is on a relatively large unsorted list filled with random numbers allowing
 // duplicated elements.
 public void testAllSecond() {
   // Make a random target list.
   int s = 1000;
   int[] target = new int[s];
   Random rand = new Random(System.currentTimeMillis());
   for (int i = 0; i < target.length; i++) target[i] = rand.nextInt(s / 2);
   // Sort the resulting list with each sorting algorithm.
   MergeSort ms = new MergeSort(target);
   QuickSort qs = new QuickSort(target);
   HeapSort hs = new HeapSort(target);
   int[] mr = ms.sort(MergeSort.ASC_DESC.DESCENDING);
   int[] qr = qs.sort(QuickSort.ASC_DESC.DESCENDING);
   int[] hr = hs.sort(HeapSort.ASC_DESC.DESCENDING);
   // Compare the results.
   /*for (int i = 0; i < target.length; i++)
   {
   	assertEquals(mr[i], qr[i]);
   	assertEquals(qr[i], hr[i]);
   }*/
   assertArrayEquals(mr, qr);
   assertArrayEquals(qr, hr);
 }
Ejemplo n.º 5
0
 @Test
 public void testMD4() {
   MAC hmac = HMAC.md4(ascii(EMPTY_STRING));
   assertArrayEquals(hex("c8d444e3153b538850e7850fa84bb247"), hmac.digest(ascii(EMPTY_STRING)));
   hmac = HMAC.md4(ascii("key"));
   assertArrayEquals(hex("8d3366c440a9c65124ab0b5f4ca27338"), hmac.digest(ascii(PANGRAM)));
 }
Ejemplo n.º 6
0
  @Test
  public void testReplaceOneValueViaFunction() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    Map map = createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys);

    for (int i = 0; i < numKeys; ++i) {
      boolean replaced = map.replaceFirstMatch(makeKey(i), NEXT_IF_EVEN);
      Assert.assertTrue(replaced);
    }

    for (int i = 0; i < numKeys; ++i) {
      Iterator iter = map.get(makeKey(i));
      for (int j = 1; j < numValuesPerKeys; ++j) {
        Assert.assertTrue(iter.hasNext());
        Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
      }
      // The last element is the replaced value.
      Assert.assertTrue(iter.hasNext());
      Assert.assertArrayEquals(makeValue(1), iter.nextAsByteArray());
      Assert.assertFalse(iter.hasNext());
      Assert.assertEquals(0, iter.available());
      iter.close();
    }
    map.close();
  }
Ejemplo n.º 7
0
  @Test
  public void testReplaceAllValuesViaFunction() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    Map map = createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys);

    for (int i = 0; i < numKeys; ++i) {
      long expectedNumReplaced = numValuesPerKeys / 2;
      long actualNumReplaced = map.replaceAllMatches(makeKey(i), NEXT_IF_EVEN);
      Assert.assertEquals(expectedNumReplaced, actualNumReplaced);
    }

    for (int i = 0; i < numKeys; ++i) {
      Iterator iter = map.get(makeKey(i));
      for (int j = 1; j < numValuesPerKeys; j += 2) {
        Assert.assertTrue(iter.hasNext());
        Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
      }
      // Replaced values have been inserted at the end.
      for (int j = 1; j < numValuesPerKeys; j += 2) {
        Assert.assertTrue(iter.hasNext());
        Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
      }
      Assert.assertFalse(iter.hasNext());
      Assert.assertEquals(0, iter.available());
      iter.close();
    }
    map.close();
  }
Ejemplo n.º 8
0
  @Test
  public void serializeStringAsAsciiBytes() throws Exception {
    final String data = "abc123";
    final Charset asciiCharset = Charset.forName("US-ASCII");
    final int loops = 1000;
    ByteArrayOutputStream out = new ByteArrayOutputStream(10);
    byte[] expecteds = new byte[] {'a', 'b', 'c', '1', '2', '3'};
    long start = 0;

    start = System.nanoTime();
    for (int i = 0; i < loops; i++) {
      AsciiUtils.writeStringAsAsciiBytes(data, out);
      out.flush();
      assertArrayEquals(expecteds, out.toByteArray());
      out.reset();
    }
    System.out.println(
        "AsciiUtils#writeStringAsAsciiBytes() elapsed time: "
            + ((System.nanoTime() - start) / 1000000)
            + " ms");

    start = System.nanoTime();
    for (int i = 0; i < loops; i++) {
      out.write(data.getBytes(asciiCharset));
      out.flush();
      assertArrayEquals(expecteds, out.toByteArray());
      out.reset();
    }
    System.out.println(
        "String#getBytes() elapsed time: " + ((System.nanoTime() - start) / 1000000) + " ms");
  }
Ejemplo n.º 9
0
 @Test
 public void testKasaFit() {
   assertArrayEquals(expected, FitCircle.kasaFit(points), 1e-10);
   assertArrayEquals(expected, FitCircle.kasaFit(noisyPoints), 1e-2);
   assertArrayEquals(expected, FitCircle.kasaFit(arcPoints), 1e-10);
   assertArrayEquals(expected, FitCircle.kasaFit(noisyArcPoints), 1);
 }
  @Test
  public void testUnshrinkEntry() throws Exception {
    ZipArchiveInputStream in =
        new ZipArchiveInputStream(new FileInputStream(getFile("SHRUNK.ZIP")));

    ZipArchiveEntry entry = in.getNextZipEntry();
    assertEquals("method", ZipMethod.UNSHRINKING.getCode(), entry.getMethod());
    assertTrue(in.canReadEntryData(entry));

    FileInputStream original = new FileInputStream(getFile("test1.xml"));
    try {
      assertArrayEquals(IOUtils.toByteArray(original), IOUtils.toByteArray(in));
    } finally {
      original.close();
    }

    entry = in.getNextZipEntry();
    assertEquals("method", ZipMethod.UNSHRINKING.getCode(), entry.getMethod());
    assertTrue(in.canReadEntryData(entry));

    original = new FileInputStream(getFile("test2.xml"));
    try {
      assertArrayEquals(IOUtils.toByteArray(original), IOUtils.toByteArray(in));
    } finally {
      original.close();
    }
  }
Ejemplo n.º 11
0
  @Test
  public void testGetCentroidDoubleArrayArray() {
    try {
      Centroid.getCentroid(badNd);
      fail("Should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    }

    // A 20-D centroid
    double[] centroid = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
    assertArrayEquals(centroid, Centroid.getCentroid(goodNd), 1E-9);

    // A 3-D array
    double[][] threeD = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}, {16, 17, 18}};
    // Its centroid
    double[] centroid3d = {8.5, 9.5, 10.5};
    assertArrayEquals(centroid3d, Centroid.getCentroid(threeD), 1E-9);

    // A 2-D array
    double[][] twoD = {{1, 2}, {4, 5}, {7, 8}, {10, 11}, {13, 14}, {16, 17}};
    // Its centroid
    double[] centroid2d = {8.5, 9.5};
    assertArrayEquals(centroid2d, Centroid.getCentroid(twoD), 1E-9);

    // A 1-D array
    double[][] oneD = {{1}, {4}, {7}, {10}, {13}, {16}};
    // Its centroid
    double[] centroid1d = {8.5};
    assertArrayEquals(centroid1d, Centroid.getCentroid(oneD), 1E-9);
  }
  @Test
  public void testTranslate() {
    short[] packed = new short[] {0, 4}, squashed = new short[] {0, 1};
    short[] translated = translate(packed, -2, -2, 60, 60);
    assertArrayEquals(squashed, translated);

    /*
    false true
    true  false
     */
    /* MOVE OVER, X 1, limit width to 2
    false true
    false true
     */
    boolean[][] grid = new boolean[][] {new boolean[] {false, true}, new boolean[] {true, false}};
    boolean[][] grid2 = new boolean[][] {new boolean[] {false, false}, new boolean[] {true, true}};
    short[] packed2 = pack(grid), packed3 = pack(grid2);

    short[] translated2 = translate(packed2, 1, 0, 2, 2);
    assertArrayEquals(packed3, translated2);
    short[] crossZeroTranslated = translate(dataCross, 0, 0, 64, 64);
    short[] crossTranslated = translate(dataCross, 1, 1, 64, 64);
    short[] crossUnTranslated = translate(crossTranslated, -1, -1, 64, 64);

    assertArrayEquals(dataCross, crossZeroTranslated);
    assertArrayEquals(dataCross, crossUnTranslated);

    short[] crossBox = translate(translate(dataCross, 25, 25, 64, 64), -50, -50, 64, 64);
    // printPacked(crossBox, 64, 64);
    assertArrayEquals(crossBox, rectangle(14, 14));
  }
Ejemplo n.º 13
0
  @Test
  public void testCopyToLocalMulti() throws Exception {
    String fName1 = UUID.randomUUID() + ".txt";
    String name1 = "local/" + fName1;
    String fName2 = UUID.randomUUID() + ".txt";
    String name2 = "local/" + fName2;

    File dir = new File("local");
    dir.mkdir();

    Resource res1 = TestUtils.writeToFS(cfg, name1);
    Resource res2 = TestUtils.writeToFS(cfg, name2);
    shell.copyToLocal(name1, "local");
    shell.copyToLocal(false, true, name2, "local");
    File fl1 = new File(name1);
    File fl2 = new File(name2);
    try {
      assertTrue(fl1.exists());
      assertTrue(fl2.exists());
      assertArrayEquals(
          FileCopyUtils.copyToByteArray(res1.getInputStream()), FileCopyUtils.copyToByteArray(fl1));
      assertArrayEquals(
          FileCopyUtils.copyToByteArray(res2.getInputStream()), FileCopyUtils.copyToByteArray(fl2));
    } finally {
      FileSystemUtils.deleteRecursively(dir);
    }
  }
Ejemplo n.º 14
0
  @Test
  public void testTranslate() {
    LogEvent logEvent =
        new LogEvent(LogLevel.ERROR, "hello {} world {}", new Object[] {"one", "two"}, null);

    LogEvent translatedLogEvent = LogUtils.translate(logEvent, "hello2 {} world2 {}");

    Assert.assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"one", "two"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {0} world2 {1}");

    Assert.assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"one", "two"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {1} world2 {0}");

    Assert.assertEquals("hello2 {} world2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"two", "one"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {0}");

    Assert.assertEquals("hello2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"one", "two"}, translatedLogEvent.getArgumentArray());

    translatedLogEvent = LogUtils.translate(logEvent, "hello2 {1}");

    Assert.assertEquals("hello2 {}", translatedLogEvent.getMessage());
    Assert.assertArrayEquals(new Object[] {"two", "two"}, translatedLogEvent.getArgumentArray());
  }
Ejemplo n.º 15
0
  @Test
  public void testRemoveOneValue() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    Map map = createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys);

    for (int i = 0; i < numKeys; ++i) {
      boolean removed = map.removeFirstEqual(makeKey(i), makeValue(123));
      Assert.assertTrue(removed);
    }

    for (int i = 0; i < numKeys; ++i) {
      Iterator iter = map.get(makeKey(i));
      int j = 0;
      for (; j < numValuesPerKeys; ++j) {
        if (j == 123) {
          // This value has been removed.
          break;
        } else {
          Assert.assertTrue(iter.hasNext());
          Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
        }
      }
      for (++j; j < numValuesPerKeys; ++j) {
        Assert.assertTrue(iter.hasNext());
        Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
      }
      Assert.assertFalse(iter.hasNext());
      Assert.assertEquals(0, iter.available());
      iter.close();
    }
    map.close();
  }
Ejemplo n.º 16
0
 @Test
 public void testPrattNewton() {
   assertArrayEquals(expected, FitCircle.prattNewton(points), 1e-10);
   assertArrayEquals(expected, FitCircle.prattNewton(noisyPoints), 1e-2);
   assertArrayEquals(expected, FitCircle.prattNewton(arcPoints), 1e-10);
   assertArrayEquals(expected, FitCircle.prattNewton(noisyArcPoints), 1);
 }
Ejemplo n.º 17
0
  @Test
  public void testRemoveOneValueViaPredicate() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    Map map = createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys);

    for (int i = 0; i < numKeys; ++i) {
      boolean removed = map.removeFirstMatch(makeKey(i), IS_EVEN);
      Assert.assertTrue(removed);
    }

    for (int i = 0; i < numKeys; ++i) {
      Iterator iter = map.get(makeKey(i));
      int j = 0;
      for (; j < numValuesPerKeys; ++j) {
        byte[] value = makeValue(j);
        if (IS_EVEN.call(ByteBuffer.wrap(value))) {
          // This value has been removed.
          break;
        } else {
          Assert.assertTrue(iter.hasNext());
          Assert.assertArrayEquals(value, iter.nextAsByteArray());
        }
      }
      for (++j; j < numValuesPerKeys; ++j) {
        Assert.assertTrue(iter.hasNext());
        Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
      }
      Assert.assertFalse(iter.hasNext());
      Assert.assertEquals(0, iter.available());
      iter.close();
    }
    map.close();
  }
Ejemplo n.º 18
0
 @Test
 public void testTaubinSVD() {
   assertArrayEquals(expected, FitCircle.taubinSVD(points), 1e-10);
   assertArrayEquals(expected, FitCircle.taubinSVD(noisyPoints), 1e-2);
   assertArrayEquals(expected, FitCircle.taubinSVD(arcPoints), 1e-10);
   assertArrayEquals(expected, FitCircle.taubinSVD(noisyArcPoints), 1);
 }
Ejemplo n.º 19
0
  @Test
  public void testReplaceAllValues() throws Exception {
    int numKeys = 1000;
    int numValuesPerKeys = 1000;
    Map map = createAndFillMap(DIRECTORY, numKeys, numValuesPerKeys);

    for (int i = 0; i < numKeys; ++i) {
      long expectedNumReplaced = 1;
      long actualNumRemoved = map.replaceAllEqual(makeKey(i), makeValue(123), makeValue(124));
      Assert.assertEquals(expectedNumReplaced, actualNumRemoved);
    }

    for (int i = 0; i < numKeys; ++i) {
      Iterator iter = map.get(makeKey(i));
      for (int j = 0; j < numValuesPerKeys; ++j) {
        if (j == 123) {
          // This value has been removed.
        } else {
          Assert.assertTrue(iter.hasNext());
          Assert.assertArrayEquals(makeValue(j), iter.nextAsByteArray());
        }
      }
      // The last element is the replaced value.
      Assert.assertTrue(iter.hasNext());
      Assert.assertArrayEquals(makeValue(124), iter.nextAsByteArray());
      Assert.assertFalse(iter.hasNext());
      Assert.assertEquals(0, iter.available());
      iter.close();
    }
    map.close();
  }
Ejemplo n.º 20
0
 @Test
 public void testHyperStable() {
   assertArrayEquals(expected, FitCircle.hyperSimple(points), 1e-6);
   assertArrayEquals(expected, FitCircle.hyperSimple(noisyPoints), 1e-2);
   assertArrayEquals(expected, FitCircle.hyperSimple(arcPoints), 1e-6);
   assertArrayEquals(expected, FitCircle.hyperSimple(noisyArcPoints), 1);
 }
  @Test
  public void testExtractTerminalSector() {
    // prepare the mock
    final HashSet<CertificateExtension> extensions = new HashSet<>();
    extensions.add(certificateExtension);

    PrimitiveTlvDataObject firstObject =
        new PrimitiveTlvDataObject(TlvConstants.TAG_80, new byte[] {1, 2, 3, 4});
    PrimitiveTlvDataObject secondObject =
        new PrimitiveTlvDataObject(TlvConstants.TAG_81, new byte[] {5, 6, 7, 8});
    final TlvDataObjectContainer dataObjects = new TlvDataObjectContainer(firstObject);
    dataObjects.addTlvDataObject(secondObject);

    new NonStrictExpectations() {
      {
        certificate.getCertificateExtensions();
        result = extensions;
        certificateExtension.getObjectIdentifier();
        result = TaOid.id_Sector;
        certificateExtension.getDataObjects();
        result = dataObjects;
      }
    };
    Deencapsulation.invoke(taProtocol, "extractTerminalSector", certificate);
    assertArrayEquals(
        firstObject.getValueField(),
        (byte[]) Deencapsulation.getField(taProtocol, "firstSectorPublicKeyHash"));
    assertArrayEquals(
        secondObject.getValueField(),
        (byte[]) Deencapsulation.getField(taProtocol, "secondSectorPublicKeyHash"));
  }
Ejemplo n.º 22
0
 @Test
 public void testLevenMarqRed() {
   assertArrayEquals(expected, FitCircle.levenMarqRed(points), 1e-10);
   assertArrayEquals(expected, FitCircle.levenMarqRed(noisyPoints), 1e-2);
   assertArrayEquals(expected, FitCircle.levenMarqRed(arcPoints), 1e-10);
   assertArrayEquals(expected, FitCircle.levenMarqRed(noisyArcPoints), 1);
 }
Ejemplo n.º 23
0
 @Test
 public void testMD2() {
   MAC hmac = HMAC.md2(ascii(EMPTY_STRING));
   assertArrayEquals(hex("6f6e031223b36cd2a997787a03d16bf5"), hmac.digest(ascii(EMPTY_STRING)));
   hmac = HMAC.md2(ascii("key"));
   assertArrayEquals(hex("13758b9534bfb38d850457814613b0c1"), hmac.digest(ascii(PANGRAM)));
 }
 @Test
 public void edgeToVector() {
   DR = DataReader.use("equationTestNodes.txt", "equationTestEdges.txt");
   DR.createNodeList();
   Edge edge1 =
       new Edge(
           DR.getNodes().get(1), DR.getNodes().get(2), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true);
   Edge edge2 =
       new Edge(
           DR.getNodes().get(2), DR.getNodes().get(3), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true);
   Edge edge3 =
       new Edge(
           DR.getNodes().get(3), DR.getNodes().get(4), 0, "", 0, "0", "0", 0.1, 0, 0, 0, 0, true);
   double[] expArr1 = new double[] {4.0, 3.0};
   double[] expArr2 = new double[] {-7.0, 1.0};
   double[] expArr3 = new double[] {-2.0, -4.0};
   assertArrayEquals(expArr1, Equation.edgeToVector(edge1), 0.001);
   assertArrayEquals(expArr2, Equation.edgeToVector(edge2), 0.001);
   assertArrayEquals(expArr3, Equation.edgeToVector(edge3), 0.001);
   double[] expArr4 = new double[] {1.0, 3.1};
   double[] expArr5 = new double[] {-7.5, 2.0};
   double[] expArr6 = new double[] {2.0, -4.7};
   assertFalse(Math.abs(expArr4[0] - Equation.edgeToVector(edge1)[0]) < 0.001);
   assertFalse(Math.abs(expArr4[1] - Equation.edgeToVector(edge1)[1]) < 0.001);
   assertFalse(Math.abs(expArr5[0] - Equation.edgeToVector(edge2)[0]) < 0.001);
   assertFalse(Math.abs(expArr5[1] - Equation.edgeToVector(edge2)[1]) < 0.001);
   assertFalse(Math.abs(expArr6[0] - Equation.edgeToVector(edge3)[0]) < 0.001);
   assertFalse(Math.abs(expArr6[1] - Equation.edgeToVector(edge3)[1]) < 0.001);
 }
Ejemplo n.º 25
0
 @Test
 public void testMD5() {
   MAC hmac = HMAC.md5(ascii(EMPTY_STRING));
   assertArrayEquals(hex("74e6f7298a9c2d168935f58c001bad88"), hmac.digest(ascii(EMPTY_STRING)));
   hmac = HMAC.md5(ascii("key"));
   assertArrayEquals(hex("80070713463e7749b90c2dc24911e275"), hmac.digest(ascii(PANGRAM)));
 }
Ejemplo n.º 26
0
 @Test
 public void testJoin() {
   assertArrayEquals(
       array(1, 2, 3, 4, 5, 6),
       toArray(Integer.class, toList(join(list(1, 2, 3).iterator(), list(4, 5, 6).iterator()))));
   assertArrayEquals(
       array(1, 2, 3),
       toArray(
           Integer.class,
           toList(
               join(
                   list(1, 2, 3).iterator(),
                   java.util.Collections.<Integer>emptyList().iterator()))));
   assertArrayEquals(
       array(1, 2, 3),
       toArray(
           Integer.class,
           toList(
               join(
                   java.util.Collections.<Integer>emptyList().iterator(),
                   list(1, 2, 3).iterator()))));
   assertEquals(
       0,
       toArray(
               Object.class,
               toList(
                   join(
                       java.util.Collections.emptyList().iterator(),
                       java.util.Collections.emptyList().iterator())))
           .length);
 }
Ejemplo n.º 27
0
 /** Test of insertElement method, of class Vector. */
 @Test
 public void testInsertElement() {
   System.out.println("insertElement");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] mass1 = {5.0, -2.9, 0.0, -50000, 9, 7.7};
   double[] mass2 = {5.0, -2.9, 7.7, 0.0, -50000, 9};
   double[] mass3 = {7.7, 5.0, -2.9, 0.0, -50000, 9};
   double element = 7.7;
   int index1 = 5;
   int index2 = 2;
   int index3 = 0;
   VectorImpl instance1 = new VectorImpl(5);
   instance1.setData(mass);
   VectorImpl instance2 = new VectorImpl(5);
   instance2.setData(mass);
   VectorImpl instance3 = new VectorImpl(5);
   instance3.setData(mass);
   // Act
   instance1.insertElement(index1, element);
   instance2.insertElement(index2, element);
   instance3.insertElement(index3, element);
   // Assert
   assertArrayEquals(mass1, instance1.getData(), 0.0);
   assertArrayEquals(mass2, instance2.getData(), 0.0);
   assertArrayEquals(mass3, instance3.getData(), 0.0);
 }
Ejemplo n.º 28
0
 @Test
 public void testConsArray() {
   assertArrayEquals(new Integer[] {0, 1, 2, 3}, Arrays.cons(Integer.class, 0, array(1, 2, 3)));
   String[] x = Arrays.cons(String.class, "0", array("1", "2", "3"));
   assertArrayEquals(new String[] {"0", "1", "2", "3"}, x);
   assertArrayEquals(new Object[] {"0", "1", "2", "3"}, x);
 }
Ejemplo n.º 29
0
 @Test
 public void testLoadFile() throws Exception {
   MemoryMap memoryMap = FileMfUlReader.loadCardFromFile("mfulc_formatted.txt");
   assertArrayEquals(
       new byte[] {0x04, (byte) 0xCE, (byte) 0x8F, (byte) 0xCD}, memoryMap.getPage(0));
   assertArrayEquals(new byte[] {(byte) 0xE1, 0x10, 0x12, 0x00}, memoryMap.getPage(3));
 }
 @Test
 public void testRule() {
   try {
     assertArrayEquals(
         new String[] {"this", "is", "a", "test."},
         runTest(TokenFilterType.CAPITALIZATION, "This is a test."));
     assertArrayEquals(
         new String[] {"the", "city", "San Francisco", "is", "in", "California."},
         runTest(TokenFilterType.CAPITALIZATION, "The city San Francisco is in California."));
     assertArrayEquals(
         new String[] {
           "some",
           "bodily",
           "fluids,",
           "such",
           "as",
           "saliva",
           "and",
           "tears,",
           "do",
           "not",
           "transmit",
           "HIV"
         },
         runTest(
             TokenFilterType.CAPITALIZATION,
             "Some bodily fluids, such as saliva and tears, do not transmit HIV"));
   } catch (TokenizerException e) {
     fail("Exception thrown when not expected!");
   }
 }