diff options
Diffstat (limited to 'vespajlib/src/test/java/com')
5 files changed, 5 insertions, 518 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java b/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java index 3bbbf3ea7de..6eb23277075 100644 --- a/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java @@ -13,6 +13,7 @@ import com.yahoo.protect.ClassValidator; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * Tests all method of NamedReader. @@ -35,8 +36,10 @@ public class NamedReaderTestCase { @Test public void testMethodMasking() { - assertEquals(0, - ClassValidator.unmaskedMethodsFromSuperclass(NamedReader.class).size()); + List<Method> unmaskedMethods = ClassValidator.unmaskedMethodsFromSuperclass(NamedReader.class); + if (! unmaskedMethods.isEmpty()) { + fail("Unmasked methods in " + NamedReader.class.getName() + ": " + unmaskedMethods); + } } private static class MarkerReader extends Reader { diff --git a/vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java b/vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java deleted file mode 100644 index 3d0c623bbf4..00000000000 --- a/vespajlib/src/test/java/com/yahoo/text/DoubleFormatterTestCase.java +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.text; - -import org.junit.Test; -import static org.junit.Assert.assertEquals; - -@SuppressWarnings("deprecation") -/** - * @author arnej27959 - */ -public class DoubleFormatterTestCase { - - @Test - public void testZero() { - String zero = DoubleFormatter.stringValue(0.0); - //assertEquals("0.0", zero); - } - - @Test - public void testOne() { - String one = DoubleFormatter.stringValue(1.0); - assertEquals("1.0", one); - } - - @Test - public void testMinusOne() { - String one = DoubleFormatter.stringValue(-1.0); - assertEquals("-1.0", one); - } - - @Test - public void testNanInf() { - String plusInf = DoubleFormatter.stringValue(Double.POSITIVE_INFINITY); - assertEquals("Infinity", plusInf); - - String notAnum = DoubleFormatter.stringValue(Double.NaN); - assertEquals("NaN", notAnum); - - String negInf = DoubleFormatter.stringValue(Double.NEGATIVE_INFINITY); - assertEquals("-Infinity", negInf); - } - - @Test - public void testSeven() { - String seven = DoubleFormatter.stringValue(7.0); - assertEquals("7.0", seven); - - seven = DoubleFormatter.stringValue(77.0); - assertEquals("77.0", seven); - - seven = DoubleFormatter.stringValue(7777.0); - assertEquals("7777.0", seven); - - seven = DoubleFormatter.stringValue(7777007777.0); - assertEquals("7.777007777E9", seven); - } - - - @Test - public void testSomeChosenNumbers() { - String s = DoubleFormatter.stringValue(4097.0); - assertEquals("4097.0", s); - - s = DoubleFormatter.stringValue(4097.5); - assertEquals("4097.5", s); - - s = DoubleFormatter.stringValue(1073741823.0); - assertEquals("1.073741823E9", s); - - s = DoubleFormatter.stringValue(1073741823.5); - assertEquals("1.0737418235E9", s); - - s = DoubleFormatter.stringValue(1073741825.5); - assertEquals("1.0737418255E9", s); - - s = DoubleFormatter.stringValue(1.23456789012345669); - assertEquals("1.2345678901234567", s); - s = DoubleFormatter.stringValue(12.3456789012345673); - assertEquals("12.345678901234567", s); - s = DoubleFormatter.stringValue(123.456789012345666); - assertEquals("123.45678901234567", s); - s = DoubleFormatter.stringValue(1234.56789012345666); - assertEquals("1234.5678901234567", s); - s = DoubleFormatter.stringValue(12345.6789012345670); - assertEquals("12345.678901234567", s); - s = DoubleFormatter.stringValue(123456.789012345674); - assertEquals("123456.78901234567", s); - s = DoubleFormatter.stringValue(1234567.89012345671); - assertEquals("1234567.8901234567", s); - - s = DoubleFormatter.stringValue(0.99); - // assertEquals("0.99", s); - - s = DoubleFormatter.stringValue(0.5); - assertEquals("0.5", s); - - s = DoubleFormatter.stringValue(0.1); - // assertEquals("0.1", s); - - s = DoubleFormatter.stringValue(0.00123456789); - // assertEquals("0.00123456789", s); - - s = DoubleFormatter.stringValue(0.0000000000001); - // assertEquals("0.0000000000001", s); - } - - @Test - public void testPowersOfTwo() { - String twos = DoubleFormatter.stringValue(2.0); - assertEquals("2.0", twos); - - twos = DoubleFormatter.stringValue(128.0); - assertEquals("128.0", twos); - - twos = DoubleFormatter.stringValue(1048576.0); - assertEquals("1048576.0", twos); - - twos = DoubleFormatter.stringValue(1073741824.0); - assertEquals("1.073741824E9", twos); - } - - @Test - public void testSmallNumbers() { - for (double d = 1.0; d > 1.0e-200; d *= 0.75) { - String fs = DoubleFormatter.stringValue(d); - String vs = String.valueOf(d); - double rp = Double.valueOf(fs); - if (d != rp) { - // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp+" diff: "+(d-rp)); - } else if (! fs.equals(vs)) { - // System.err.println("string rep differs: "+vs+" became "+fs); - } - assertEquals(d, rp, 1.0e-7*d); - } - } - - @Test - public void testVerySmallNumbers() { - for (double d = 1.0; d > 1.0e-200; d *= 0.5) { - String fs = DoubleFormatter.stringValue(d); - String vs = String.valueOf(d); - double rp = Double.valueOf(fs); - if (d != rp) { - // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp+" diff: "+(d-rp)); - } else if (! fs.equals(vs)) { - // System.err.println("string rep differs: "+vs+" became "+fs); - } - assertEquals(d, rp, 1.0e-13*d); - } - } - - @Test - public void testVeryVerySmallNumbers() { - for (double d = 1.0e-200; d > 0; d *= 0.5) { - String fs = DoubleFormatter.stringValue(d); - String vs = String.valueOf(d); - double rp = Double.valueOf(fs); - if (d != rp) { - // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp+" diff: "+(d-rp)); - } else if (! fs.equals(vs)) { - // System.err.println("string rep differs: "+vs+" became "+fs); - } - assertEquals(d, rp, 1.0e-13*d); - } - } - - @Test - public void testVeryBigNumbers() { - for (double d = 1.0; d < Double.POSITIVE_INFINITY; d *= 2.0) { - String fs = DoubleFormatter.stringValue(d); - String vs = String.valueOf(d); - double rp = Double.valueOf(fs); - if (d != rp) { - // System.err.println("differs: "+d+" became "+fs+" then instead: "+rp); - } else if (! fs.equals(vs)) { - // System.err.println("string rep differs: "+vs+" became "+fs); - } - assertEquals(d, rp, 1.0e-13*d); - } - - assertEquals("1.0E200", String.valueOf(1.0e+200)); - - String big = DoubleFormatter.stringValue(1.0e+200); - assertEquals("1.0E200", big); - - big = DoubleFormatter.stringValue(1.0e+298); - assertEquals("1.0E298", big); - - big = DoubleFormatter.stringValue(1.0e+299); - assertEquals("1.0E299", big); - - big = DoubleFormatter.stringValue(1.0e+300); - assertEquals("1.0E300", big); - - } - - @Test - public void testRandomNumbers() { - java.util.Random rgen = new java.util.Random(0xCafeBabe); - for (int i = 0; i < 123456; i++) { - double d = rgen.nextDouble(); - } - } - -} diff --git a/vespajlib/src/test/java/com/yahoo/text/DoubleParserTestCase.java b/vespajlib/src/test/java/com/yahoo/text/DoubleParserTestCase.java deleted file mode 100644 index a48a1b6a943..00000000000 --- a/vespajlib/src/test/java/com/yahoo/text/DoubleParserTestCase.java +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.text; - -import org.junit.Test; -import static org.junit.Assert.assertEquals; - -@SuppressWarnings("deprecation") -/** - * @author arnej27959 - */ -public class DoubleParserTestCase { - - @Test - public void testZero() { - String[] zeros = { - "0", - "0.", - ".0", - "0.0", - "0.0e0", - "0.0e99", - "0.0e+300", - "0.0e-42" - }; - for (String s : zeros) { - double d = DoubleParser.parse(s); - assertEquals(0.0, d, 0); - } - } - - @Test - public void testOne() { - String[] ones = { - "1", - "1.", - "1.0", - "+1", - "10.0e-1", - "0.1e1", - "1000.0e-3", - ".001e+3", - }; - for (String s : ones) { - System.out.println("parsing: '"+s+"' now"); - double d = DoubleParser.parse(s); - System.out.println("expected: 1.0"); - System.out.println("actual: "+d); - assertEquals(1.0, d, 0); - } - } - - @Test - public void testMinusOne() { - String[] numbers = { - "-1", - "-1.0", - "-1.", - "-1e0", - "-10e-1", - }; - for (String s : numbers) { - System.out.println("parsing: '"+s+"' now"); - double d = DoubleParser.parse(s); - System.out.println("expected: -1.0"); - System.out.println("actual: "+d); - assertEquals(-1.0, d, 0); - } - } - - @Test - public void testNanInf() { - String[] numbers = { - "NaN", - "Infinity", - "-Infinity", - "+Infinity", - "+NaN", - "-NaN" - }; - for (String s : numbers) { - System.out.println("parsing: '"+s+"' now"); - double d1 = Double.parseDouble(s); - double d2 = DoubleParser.parse(s); - long lb1 = Double.doubleToRawLongBits(d1); - long lb2 = Double.doubleToRawLongBits(d2); - assertEquals(lb1, lb2, 0); - } - } - - @Test - public void testSeven() { - String[] sevens = { - "7", - "7.", - "7.0", - "70.0e-1", - "0.7e1", - "7000.0e-3", - ".007e+3", - }; - for (String s : sevens) { - System.out.println("parsing: '"+s+"' now"); - double d = DoubleParser.parse(s); - System.out.println("expected: 7.0"); - System.out.println("actual: "+d); - assertEquals(7.0, d, 0); - } - } - - @Test - public void testVerySmallNumbers() { - String[] numbers = { - "1.e-320", - "-1.e-320", - "1.0013378241589014e-303" - }; - for (String s : numbers) { - System.out.println("parsing: '"+s+"' now"); - double d1 = Double.parseDouble(s); - double d2 = DoubleParser.parse(s); - System.out.println("expected: "+d1); - System.out.println("actual: "+d2); - assertEquals(d1, d2, 0); - } - } - - @Test - public void testRandomNumbers() { - java.util.Random rgen = new java.util.Random(0xCafeBabe); - for (int i = 0; i < 123456; i++) { - double d = rgen.nextDouble(); - int exp = rgen.nextInt(); - d *= Math.pow(1.0000006, exp); - String s = Double.toString(d); - double d2 = Double.parseDouble(s); - double d3 = DoubleParser.parse(s); - - if (d != d2) { - System.out.println("WARNING: value ["+d+"] parses as ["+d2+"] by Java"); - } - double allow = 1.0e-14 * d2; - if (allow < 0) { - allow = -allow; - } - if (d2 != d3) { - long lb2 = Double.doubleToRawLongBits(d2); - long lb3 = Double.doubleToRawLongBits(d3); - if (lb2 - lb3 > 15 || lb3 - lb2 > 15) { - System.out.println("WARNING: string '"+s+"' parses as"); - System.out.println("["+d2+"] by Java, ["+d3+"] by our method"); - System.out.println("["+Long.toHexString(lb2)+"] bits vs ["+Long.toHexString(lb3)+"]"); - System.out.println("==> "+(lb2 - lb3)+" <== diff value"); - } - } - assertEquals(d2, d3, allow); - } - } - -} diff --git a/vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java b/vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java deleted file mode 100644 index a5925df2caf..00000000000 --- a/vespajlib/src/test/java/com/yahoo/text/DoubleToStringBenchmark.java +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.text; - -import org.junit.Ignore; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; -import java.util.Random; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; - -@SuppressWarnings("deprecation") -/** - * @author arnej27959 - */ -public class DoubleToStringBenchmark { - - @Test - @Ignore - public void benchmarkStringConstruction() throws Exception { - List<Class<? extends Benchmark.Task>> taskList = Arrays.asList(UseStringValueOf.class, - UseDoubleFormatter.class, - UseDoubleFormatter.class, - UseStringValueOf.class, - UseStringValueOf.class, - UseDoubleFormatter.class, - UseDoubleFormatter.class, - UseStringValueOf.class, - UseDoubleFormatter.class, - UseStringValueOf.class); - - int maxThreads = 256; - int dummy = 0; - System.out.print("warmup"); - for (Class<? extends Benchmark.Task> taskClass : taskList) { - dummy += runBenchmark(maxThreads, taskClass); - System.out.print("."); - } - System.out.println(" " + dummy); - - System.out.format("%-35s", ""); - for (int numThreads = 1; numThreads <= maxThreads; numThreads *= 2) { - System.out.format("%13s t ", numThreads); - } - System.out.println(); - for (Class<? extends Benchmark.Task> taskClass : taskList) { - System.out.format("%-35s", taskClass.getSimpleName()); - for (int numThreads = 1; numThreads <= maxThreads; numThreads *= 2) { - System.out.format("%15d ", runBenchmark(numThreads, taskClass)); - } - System.out.println(); - } - } - - private long runBenchmark(int numThreads, Class<? extends Benchmark.Task> taskClass) throws Exception { - return new Benchmark.Builder() - .setNumIterationsPerThread(80000) - .setNumThreads(numThreads) - .setTaskClass(taskClass) - .build() - .run(); - } - - public static class UseStringValueOf implements Benchmark.Task { - - private long timeIt(Random randomGen, int num) { - long before = System.nanoTime(); - - String str = null; - double v = 0.0; - for (int i = 0; i < num; ++i) { - v = randomGen.nextDouble() * 1.0e-2; - str = String.valueOf(v); - } - - long after = System.nanoTime(); - assertEquals(""+v, str); - return after - before; - } - - @Override - public long run(CyclicBarrier barrier, int numIterations) throws Exception { - Random randomGen = new Random(0xDeadBeef); - barrier.await(600, TimeUnit.SECONDS); - long t1 = timeIt(randomGen, numIterations / 4); - long t2 = timeIt(randomGen, numIterations / 2); - long t3 = timeIt(randomGen, numIterations / 4); - return t2; - } - } - - public static class UseDoubleFormatter implements Benchmark.Task { - - private long timeIt(Random randomGen, int num) { - long before = System.nanoTime(); - - String str = null; - double v = 0.0; - for (int i = 0; i < num; ++i) { - v = randomGen.nextDouble() * 1.0e-2; - str = DoubleFormatter.stringValue(v); - } - - long after = System.nanoTime(); - // assertEquals(""+v, str); - return after - before; - } - - - @Override - public long run(CyclicBarrier barrier, int numIterations) throws Exception { - Random randomGen = new Random(0xDeadBeef); - barrier.await(600, TimeUnit.SECONDS); - long t1 = timeIt(randomGen, numIterations / 4); - long t2 = timeIt(randomGen, numIterations / 2); - long t3 = timeIt(randomGen, numIterations / 4); - return t2; - } - } - -} diff --git a/vespajlib/src/test/java/com/yahoo/text/LanguageHacksTestCase.java b/vespajlib/src/test/java/com/yahoo/text/LanguageHacksTestCase.java deleted file mode 100644 index 4231c6ede02..00000000000 --- a/vespajlib/src/test/java/com/yahoo/text/LanguageHacksTestCase.java +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.text; - -import org.junit.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * Test for LanguageHacks. - * $Id$ - */ -@SuppressWarnings("deprecation") -public class LanguageHacksTestCase { - - @Test - public void isCJK() { - assertFalse("NULL language", LanguageHacks.isCJK(null)); - assertTrue(LanguageHacks.isCJK("zh")); - assertFalse("Norwegian is CJK", LanguageHacks.isCJK("no")); - } - - @Test - public void yellDesegments() { - assertFalse("NULL language", LanguageHacks.yellDesegments(null)); - assertTrue(LanguageHacks.yellDesegments("de")); - assertFalse("Norwegian desegments", LanguageHacks.yellDesegments("no")); - } -} |