Esempio n. 1
0
  @Test
  public void toStringRoundMin_1Arg() {
    System.out.println("toStringRoundMin(2)");
    System.out.println("===================");
    ByteSize bc = null;

    bc = new ByteSize(1024);
    System.out.println("" + bc.toStringRoundMin(2));
    //        assertTrue(bc.toString().equalsIgnoreCase("1kb"));

    bc = new ByteSize(1024 + 15);
    System.out.println("" + bc.toStringRoundMin(2));
    //        assertTrue(bc.toString().equalsIgnoreCase("1kb 15b"));

    bc = new ByteSize(1024 * 1024 * 2 + 1024 + 15);
    String s = "" + bc.toStringRoundMin(2);
    System.out.println(s);
    //        assertTrue(bc.toString().equalsIgnoreCase("2mb 1kb 15b"));

    bc = new ByteSize(-(1024 * 1024 * 3 + 1024 * 2 + 15));
    s = "" + bc.toStringRoundMin(3);
    System.out.println(s);
    //        assertTrue(bc.toString().equalsIgnoreCase("-3mb 2kb 15b"));
  }
Esempio n. 2
0
  @Test
  public void testToString() {
    System.out.println("testToString");
    System.out.println("============");
    ByteSize bc = null;

    bc = new ByteSize(1024);
    System.out.println("" + bc.toString());
    assertTrue(bc.toString().equalsIgnoreCase("1kb"));

    bc = new ByteSize(1024 + 15);
    System.out.println("" + bc.toString());
    assertTrue(bc.toString().equalsIgnoreCase("1kb 15b"));

    bc = new ByteSize(1024 * 1024 * 2 + 1024 + 15);
    System.out.println("" + bc.toString());
    assertTrue(bc.toString().equalsIgnoreCase("2mb 1kb 15b"));

    bc = new ByteSize(-(1024 * 1024 * 3 + 1024 * 2 + 15));
    System.out.println("" + bc.toString());
    assertTrue(bc.toString().equalsIgnoreCase("-3mb 2kb 15b"));
  }
Esempio n. 3
0
  @Test
  public void parseTest() {
    System.out.println("parseTest");
    System.out.println("=========");

    ByteSize bs;

    bs = ByteSize.parse("0");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(0)));

    bs = ByteSize.parse("1");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(1)));

    bs = ByteSize.parse("1k");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(1024)));

    bs = ByteSize.parse("2m");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(1024 * 1024 * 2)));

    bs = ByteSize.parse("- 2 m");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(-1024 * 1024 * 2)));

    bs = ByteSize.parse("2m 4k 6");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf((1024 * 1024 * 2 + 1024 * 4 + 6))));

    bs = ByteSize.parse("2m 4k 8b");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(1024 * 1024 * 2 + 1024 * 4 + 8)));

    bs = ByteSize.parse("2.5m");
    assertTrue(bs != null);
    assertTrue(bs.getSize().equals(BigInteger.valueOf(1024 * 1024 * 2 + 1024 * 512)));
    System.out.println(bs.toString());

    bs = ByteSize.parse("2.4m");
    assertTrue(bs != null);
    System.out.println(bs.toString());

    bs = ByteSize.parse("1M");
    assertTrue(bs != null);

    System.out.println(bs.toString());
    assertTrue(bs.getSize().equals(BigInteger.valueOf(1024 * 1024)));
  }