src_fm_fc_ms_ff stringlengths 43 86.8k | target stringlengths 20 276k |
|---|---|
CleanFormatter extends Formatter { public static String prependToLines(String prepend, String lines) { if (lines == null) return null; if (prepend == null) return lines; StringBuilder result = new StringBuilder(); boolean hasFinalNL = lines.endsWith(NL); StringTokenizer divided = new StringTokenizer(lines, NL); while (... | @Test public void testPrepend() { String lines = CleanFormatter.prependToLines("a","bbb"+NL+"ccc"); assertTrue(lines.equals("abbb"+NL+"accc")); } |
AtomicDouble extends Number implements java.io.Serializable { public final double addAndGet(double delta) { for (;;) { long lexpect = _al.get(); double expect = d(lexpect); double update = expect+delta; long lupdate = l(update); if (_al.compareAndSet(lexpect,lupdate)) return update; } } AtomicDouble(); AtomicDouble(do... | @Test public void testAddAndGet() { double expected = 0.0; for (int i=0; i<10; ++i) { double nd = RANDOM.nextDouble(); expected += nd; double actual = ad.addAndGet(nd); assertEquals(expected, ad.get(),epsilon); } } |
AtomicDouble extends Number implements java.io.Serializable { public final boolean compareAndSet(double expect, double update) { return _al.compareAndSet(l(expect),l(update)); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); final boo... | @Test public void testCompareAndSet() { ad.compareAndSet(1.0,2.0); assertEquals(0.0,ad.get()); ad.compareAndSet(0.0,1.0); assertEquals(1.0,ad.get()); } |
AtomicDouble extends Number implements java.io.Serializable { public final boolean weakCompareAndSet(double expect, double update) { return _al.weakCompareAndSet(l(expect),l(update)); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); f... | @Test public void testWeakCompareAndSet() { ad.weakCompareAndSet(0.0,1.0); assertEquals(1.0,ad.get()); } |
AtomicDouble extends Number implements java.io.Serializable { public final double incrementAndGet() { return addAndGet(1.0); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); final boolean compareAndSet(double expect, double update); f... | @Test public void testIncrementAndGet() { double val; for (int i=0; i<10; ++i) { val = ad.get(); assertEquals((double)(i ),val,1.0E-8); val = ad.incrementAndGet(); assertEquals((double)(i+1),val,1.0E-8); val = ad.get(); assertEquals((double)(i+1),val,1.0E-8); } } |
AtomicDouble extends Number implements java.io.Serializable { public final double decrementAndGet() { return addAndGet(-1.0); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); final boolean compareAndSet(double expect, double update); ... | @Test public void testDecrementAndGet() { double val = 10.0; ad.set(val); for (int i=10; i>0; --i) { val = ad.get(); assertEquals((double)(i ),val,1.0E-8); val = ad.decrementAndGet(); assertEquals((double)(i-1),val,1.0E-8); val = ad.get(); assertEquals((double)(i-1),val,1.0E-8); } } |
AtomicDouble extends Number implements java.io.Serializable { public final double getAndIncrement() { return getAndAdd(1.0); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); final boolean compareAndSet(double expect, double update); f... | @Test public void testGetAndIncrement() { double val; for (int i=0; i<10; ++i) { val = ad.get(); assertEquals((double)(i ),val,1.0E-8); val = ad.getAndIncrement(); assertEquals((double)(i ),val,1.0E-8); val = ad.get(); assertEquals((double)(i+1),val,1.0E-8); } } |
AtomicDouble extends Number implements java.io.Serializable { public final double getAndDecrement() { return getAndAdd(-1.0); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); final boolean compareAndSet(double expect, double update); ... | @Test public void testGetAndDecrement() { double val = 10.0; ad.set(val); for (int i=10; i>0; --i) { val = ad.get(); assertEquals((double)(i ),val,1.0E-8); val = ad.getAndDecrement(); assertEquals((double)(i ),val,1.0E-8); val = ad.get(); assertEquals((double)(i-1),val,1.0E-8); } } |
AtomicDouble extends Number implements java.io.Serializable { public final double getAndSet(double value) { return d(_al.getAndSet(l(value))); } AtomicDouble(); AtomicDouble(double value); final double get(); final void set(double value); final double getAndSet(double value); final boolean compareAndSet(double expect,... | @Test public void testGetAndSet() { double expected0 = RANDOM.nextDouble(); double expected1 = RANDOM.nextDouble(); AtomicDouble ad = new AtomicDouble(expected0); double actual0 = ad.getAndSet(expected1); double actual1 = ad.get(); assertEquals(expected0,actual0,epsilon); assertEquals(expected1,actual1,epsilon); } |
Localize { public Localize(final Class<?> clazz) { this(clazz, null); } Localize(final Class<?> clazz); Localize(final Class<?> clazz, final String resourceBundleName); Localize(final Class<?> clazz, final String resourceBundleName, final Locale locale); String format(final String key, final Object... args); static R... | @Test public void testLocalize() { { final Localize dfault = new Localize(LocalizeTest.class); final String sDefault = dfault.format("msg1", 3.14, 42); assertEquals("A number 3.14000 here, and another #42",sDefault); } { final Localize fr = new Localize(LocalizeTest.class, null, Locale.FRENCH); final int i = 42; final ... |
Localize { public static String getMessage(final Throwable throwable) { if (throwable.getCause() == null) { final String localizedMessage = throwable.getLocalizedMessage(); if (localizedMessage != null) { return localizedMessage; } final String message = throwable.getMessage(); if (message != null) { return message; } ... | @Test public static void testLocalizeThrowable() { final IOException ioException = new IOException("ioe"); assertEquals("ioe",Localize.getMessage(ioException)); { final IllegalArgumentException e = new IllegalArgumentException(ioException); assertEquals("ioe",Localize.getMessage(e)); } { final String better = "Bad argu... |
RTree extends AbstractSet<Object> { public Iterator<Object> iterator() { return new RTreeIterator(); } RTree(int ndim, int nmin, int nmax); RTree(int ndim, int nmin, int nmax, Boxer boxer); int size(); void clear(); boolean isEmpty(); boolean add(Object object); int addPacked(Object[] objects); boolean remove(Object o... | @Test public void testIterator() { RTree rt = new RTree(3,4,12); int n = 100; for (int i=0; i<n; ++i) rt.add(randomBox(0.2f)); Iterator<Object> rti = rt.iterator(); Object box = rti.next(); rt.remove(box); rt.add(box); boolean cmeThrown = false; try { rti.next(); } catch (ConcurrentModificationException cme) { cmeThrow... |
Localize { public static String timeWords(long seconds) { if (seconds == 0) { return filter("0 ${seconds}", Localize.class); } String result = ""; long minutes = seconds/60; long hours = minutes/60; long days = hours/24; seconds %= 60; minutes %= 60; hours %= 24; if (days >= 10) { if (hours >=12) ++days; hours = minute... | @Test public static void testLocalizeOld() throws Exception { { long seconds =(29L + 60*(9)); String words = timeWords(seconds); assertEquals(words,"9 minutes 29 seconds"); } { long seconds =(29L + 60*(10)); String words = timeWords(seconds); assertEquals(words,"10 minutes"); } { long seconds =(30L + 60*(10)); String w... |
Almost implements Serializable, Comparator<Number> { public double divide(final double top, final double bottom, final boolean limitIsOne) { return divide(top, bottom, (limitIsOne) ? 1.0 : 0.0); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigit... | @Test public void testSafeDivision() { double big = 0.01 * Float.MAX_VALUE; assertEquals(-0.5, a.divide(-1.0, 2.0, 0.0)); assertEquals(-0.5, a.divide( 1.0,-2.0, 0.0)); assertEquals( 1.0, a.divide( 0.0, 0.0, 1.0)); assertEquals( 1.0, a.divide(-1.0,-1.0, 1.0)); assertEquals( 1.0, a.divide(-1.0,-1.0, true)); assertEquals(... |
Almost implements Serializable, Comparator<Number> { public double reciprocal(final double value) { return divide(1.0, value, 0.0); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean isDouble); double getEpsilon(); doubl... | @Test public void testReciprocal() { assertEquals(0.5, a.reciprocal(2.0)); } |
Almost implements Serializable, Comparator<Number> { public boolean between(final double x, final double x1, final double x2) { return ((cmp(x, x1) * cmp(x, x2)) <= 0); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean ... | @Test public void testBetween() { assertTrue(a.between(1., 0., 2.)); assertTrue(a.between(-1., 0., -2.)); assertTrue(a.between(-1., -0.5, -2.)); assertTrue(a.between(1., 1.000000000001, 2.)); assertTrue(a.between(-1., -1.000000000001, -2.)); } |
Almost implements Serializable, Comparator<Number> { public int outside(final double x, final double x1, final double x2) { int i = 0; if (between(x, x1, x2)) { i = 0; } else if (between(x1, x, x2)) { i = -1; } else if (between(x2, x, x1)) { i = 1; } return i; } Almost(); Almost(final double epsilon, final double minV... | @Test public void testOutside() { assertEquals(0,a.outside(1., 0., 2.)); assertEquals(0,a.outside(1., 0.5, 2.)); assertEquals(0,a.outside(-1., 0., -2.)); assertEquals(0,a.outside(-1., -0.5, -2.)); assertEquals(-1,a.outside(-1., -1.1, -2.)); assertEquals( 1,a.outside(-1., -0.5, -0.9)); assertEquals(0,a.outside(1., 1.000... |
Almost implements Serializable, Comparator<Number> { @Override public int compare(final Number n1, final Number n2) { return cmp(n1.doubleValue(), n2.doubleValue()); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean isD... | @Test public void testCompare() { assertTrue (a.cmp(1., 0.) > 0); assertTrue (a.cmp(0., 1.) < 0); assertEquals(0,a.cmp(1., 1.)); assertEquals(0,a.cmp(0., 0.)); assertEquals(0,a.cmp(1., 1.000000000001)); Integer i = 1; Integer j = 1; assertEquals(0,a.compare(i,j)); } |
Almost implements Serializable, Comparator<Number> { public boolean zero(double r) { if (r < 0.0) { r = -r; } return (r < _minValue); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean isDouble); double getEpsilon(); dou... | @Test public void testZero() { assertTrue (a.zero(0.)); assertTrue (a.zero(a.getMinValue()/2.)); assertFalse(a.zero(a.getMinValue()*2.)); } |
Almost implements Serializable, Comparator<Number> { public double getEpsilon() { return _epsilon; } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean isDouble); double getEpsilon(); double getMinValue(); boolean between(... | @Test public void testEpsilon() { assertNotEquals(1.,1.+a.getEpsilon()); assertNotEquals(1.,1.-a.getEpsilon()); } |
Almost implements Serializable, Comparator<Number> { public double getMinValue() { return _minValue; } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean isDouble); double getEpsilon(); double getMinValue(); boolean betwee... | @Test public void testGetMinValue() { assertNotEquals(0.,a.getMinValue()); assertTrue (a.getMinValue()/2.>0.); } |
Almost implements Serializable, Comparator<Number> { @Override public int hashCode() { return Long.valueOf(Double.doubleToLongBits(_epsilon) ^ Double.doubleToLongBits(_minValue)).intValue(); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); ... | @Test public void testHashCode () { Almost a = new Almost(0.001,0.000001); assertEquals(0,a.hashCodeOf(0.00000001,100)); assertEquals(1,a.hashCodeOf(0.99999999,100)); assertEquals(1,a.hashCodeOf(1.00000001,100)); assertEquals(123456789L,a.hashCodeOf(123456789L,100)); assertEquals (a.hashCodeOf( 3.1415,4), a.hashCodeOf(... |
ArgsParser { public static boolean toBoolean(String s) throws OptionException { s = s.toLowerCase(); if (s.equals("true")) return true; if (s.equals("false")) return false; throw new OptionException("the value "+s+" is not a valid boolean"); } ArgsParser(String[] args, String shortOpts); ArgsParser(String[] args, Stri... | @Test(expectedExceptions = ArgsParser.OptionException.class) public void testBooleanConverterShouldThrowException() throws Exception { ArgsParser.toBoolean("true"); ArgsParser.toBoolean("Foo"); } |
Almost implements Serializable, Comparator<Number> { public boolean equal(final double r1, final double r2) { return (cmp(r1, r2) == 0); } Almost(); Almost(final double epsilon, final double minValue); Almost(final double epsilon); Almost(int significantDigits); Almost(final boolean isDouble); double getEpsilon(); ... | @Test(expectedExceptions = IllegalArgumentException.class) public void testNaNsThrowsException() { Almost.FLOAT.equal(0,Float.NaN); Almost.FLOAT.equal(0,Double.NaN); } |
ParameterSet implements Cloneable, Externalizable { public Object clone() throws CloneNotSupportedException { try { ParameterSet ps = (ParameterSet)super.clone(); ps._parent = null; ps._pars = new LinkedHashMap<String, Parameter>(); ps._parsets = new LinkedHashMap<String, ParameterSet>(); return ps.replaceWith(this); }... | @Test public void testClone() { ParameterSet root = new ParameterSet("root"); String s1 = root.toString(); ParameterSet foo = root.addParameterSet("foo"); foo.addParameter("bar"); try { ParameterSet temp = (ParameterSet)root.clone(); temp.remove("foo"); root.replaceWith(temp); String s2 = root.toString(); assertTrue(s1... |
UnitSphereSampling { private static void testSymmetry(UnitSphereSampling uss) { int mi = uss.getMaxIndex(); for (int i=1,j=-i; i<=mi; ++i,j=-i) { float[] p = uss.getPoint(i); float[] q = uss.getPoint(j); assert p[0]==-q[0]; assert p[1]==-q[1]; assert p[2]==-q[2]; } int npoint = 10000; for (int ipoint=0; ipoint<npoint; ... | @Test public void testSymmetry() { testSymmetry(8); testSymmetry(16); } |
UnitSphereSampling { private static void testInterpolation(UnitSphereSampling uss) { int mi = uss.getMaxIndex(); int nf = 1+2*mi; float[] fi = new float[nf]; for (int i=1; i<=mi; ++i) { float[] p = uss.getPoint( i); float[] q = uss.getPoint(-i); fi[i ] = func(p[0],p[1],p[2]); fi[nf-i] = func(q[0],q[1],q[2]); } float em... | @Test public void testInterpolation() { testInterpolation(16,0.0001f); } |
UnitSphereSampling { private static void testTriangle(UnitSphereSampling uss) { int npoint = 1000000; for (int ipoint=0; ipoint<npoint; ++ipoint) { float[] p = randomPoint(); int i = uss.getIndex(p); int[] abc = uss.getTriangle(p); int ia = abc[0], ib = abc[1], ic = abc[2]; float[] q = uss.getPoint(i); float[] qa = uss... | @Test public void testTriangle() { testTriangle(8); testTriangle(16); } |
ArrayMath { public static int binarySearch(byte[] a, byte x) { return binarySearch(a,x,a.length); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); st... | @Test public void testBinarySearch() { double[] a = {}; checkSearch(a,1); double[] a0 = {2}; checkSearch(a0,1); checkSearch(a0,2); checkSearch(a0,3); double[] a13 = {1,3}; checkSearch(a13,0); checkSearch(a13,1); checkSearch(a13,2); checkSearch(a13,3); checkSearch(a13,4); double[] a31 = {3,1}; checkSearch(a31,0); checkS... |
ArrayMath { public static float sin(float x) { return (float)Math.sin(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double ... | @Test public void testSin() { assertEq(0f,sin(FLT_PI)); assertEq(0d,sin(DBL_PI)); float[] f1 = rampfloat(0,4,5); float[][] f2 = rampfloat(0,4,4,5,5); float[][][] f3 = rampfloat(0,4,4,4,5,5,5); float[] g1 = zerofloat(5); float[][] g2 = zerofloat(5,5); float[][][] g3 = zerofloat(5,5,5); double[] d1 = rampdouble(0,4,5); d... |
ArrayMath { public static float cos(float x) { return (float)Math.cos(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double ... | @Test public void testCos() { assertEq(1f,cos(2.0f*FLT_PI)); assertEq(1d,cos(2.0d*DBL_PI)); float[] g1 = zerofloat(5); float[][] g2 = zerofloat(5,5); float[][][] g3 = zerofloat(5,5,5); float[] f1 = rampfloat(0,4,5); float[][] f2 = rampfloat(0,4,4,5,5); float[][][] f3 = rampfloat(0,4,4,4,5,5,5); double[] e1 = zerodouble... |
ArrayMath { public static float tan(float x) { return (float)Math.tan(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double ... | @Test public void testTan() { assertEq(1.0f,tan(FLT_PI/4.0f)); assertEq(1.0d,tan(DBL_PI/4.0d)); } |
ArrayMath { public static float asin(float x) { return (float)Math.asin(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(doubl... | @Test public void testASin() { assertEq(FLT_PI/2.0f,asin(1.0f)); assertEq(DBL_PI/2.0d,asin(1.0d)); } |
ArgsParser { public static double toDouble(String s) throws OptionException { try { return Double.valueOf(s); } catch (NumberFormatException e) { throw new OptionException("the value "+s+" is not a valid double"); } } ArgsParser(String[] args, String shortOpts); ArgsParser(String[] args, String shortOpts, String[] lon... | @Test(expectedExceptions = ArgsParser.OptionException.class) public void testDoubleConverterShouldThrowException() throws Exception { ArgsParser.toDouble("1.986"); ArgsParser.toDouble("Foo"); } |
ArrayMath { public static float acos(float x) { return (float)Math.acos(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(doubl... | @Test public void testACos() { assertEq(FLT_PI/2.0f,acos(0.0f)); assertEq(DBL_PI/2.0d,acos(0.0d)); } |
ArrayMath { public static float atan(float x) { return (float)Math.atan(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(doubl... | @Test public void testATan() { assertEq(FLT_PI/4.0f,atan(1.0f)); assertEq(DBL_PI/4.0d,atan(1.0d)); } |
ArrayMath { public static float atan2(float y, float x) { return (float)Math.atan2(y,x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static doub... | @Test public void testATan2() { assertEq(FLT_PI/2.0f,atan2(1.0f,0.0f)); assertEq(DBL_PI/2.0d,atan2(1.0d,0.0d)); assertEq(-3.0f*FLT_PI/4.0f,atan2(-1.0f,-1.0f)); assertEq(-3.0d*DBL_PI/4.0d,atan2(-1.0d,-1.0d)); } |
ArrayMath { public static float log(float x) { return (float)Math.log(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double ... | @Test public void testLog() { assertEq(1.0f,log(exp(1.0f))); assertEq(1.0d,log(exp(1.0d))); } |
ArrayMath { public static float ceil(float x) { return (float)Math.ceil(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(doubl... | @Test public void testCeil() { assertEq(4.0f,ceil(FLT_PI)); assertEq(4.0d,ceil(DBL_PI)); assertEq(-3.0f,ceil(-FLT_PI)); assertEq(-3.0d,ceil(-DBL_PI)); } |
ArrayMath { public static float floor(float x) { return (float)Math.floor(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(dou... | @Test public void testFloor() { assertEq(3.0f,floor(FLT_PI)); assertEq(3.0d,floor(DBL_PI)); assertEq(-4.0f,floor(-FLT_PI)); assertEq(-4.0d,floor(-DBL_PI)); } |
ArrayMath { public static float rint(float x) { return (float)Math.rint(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(doubl... | @Test public void testRoundInt() { assertEq(3.0f,rint(FLT_PI)); assertEq(3.0d,rint(DBL_PI)); assertEq(-3.0f,rint(-FLT_PI)); assertEq(-3.0d,rint(-DBL_PI)); } |
ArrayMath { public static int round(float x) { return Math.round(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x); s... | @Test public void testRound() { assertEq(3,round(FLT_PI)); assertEq(3,round(DBL_PI)); assertEq(-3,round(-FLT_PI)); assertEq(-3,round(-DBL_PI)); assertEq(3,round(FLT_E)); assertEq(3,round(DBL_E)); assertEq(-3,round(-FLT_E)); assertEq(-3,round(-DBL_E)); } |
ArrayMath { public static float signum(float x) { return (x>0.0f)?1.0f:((x<0.0f)?-1.0f:0.0f); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static... | @Test public void testSignum() { assertEq(1.0f,signum(FLT_PI)); assertEq(1.0d,signum(DBL_PI)); assertEq(-1.0f,signum(-FLT_PI)); assertEq(-1.0d,signum(-DBL_PI)); assertEq(0.0f,signum(0.0f)); assertEq(0.0d,signum(0.0d)); } |
ArrayMath { public static int abs(int x) { return (x>=0)?x:-x; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x); static ... | @Test public void testAbs() { assertEq(2,abs(2)); assertEq(2L,abs(2L)); assertEq(2.0f,abs(2.0f)); assertEq(2.0d,abs(2.0d)); assertEq(2,abs(-2)); assertEq(2L,abs(-2L)); assertEq(2.0f,abs(-2.0f)); assertEq(2.0d,abs(-2.0d)); assertEquals(0, Float.floatToIntBits(abs(0.0f))); assertEquals(0, Double.doubleToLongBits(abs(0.0d... |
ArgsParser { public static float toFloat(String s) throws OptionException { try { return Float.valueOf(s); } catch (NumberFormatException e) { throw new OptionException("the value "+s+" is not a valid float"); } } ArgsParser(String[] args, String shortOpts); ArgsParser(String[] args, String shortOpts, String[] longOpt... | @Test(expectedExceptions = ArgsParser.OptionException.class) public void testFloatConverterShouldThrowException() throws Exception { ArgsParser.toFloat("1.986"); ArgsParser.toFloat("Foo"); } |
ArrayMath { public static int max(int a, int b) { return (a>=b)?a:b; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x); s... | @Test void testMax() { assertEq(4,max(1,3,4,2)); assertEq(4L,max(1L,3L,4L,2L)); assertEq(4.0f,max(1.0f,3.0f,4.0f,2.0f)); assertEq(4.0d,max(1.0d,3.0d,4.0d,2.0d)); assertEq(4,max(1,3,4)); assertEq(4L,max(1L,3L,4L)); assertEq(4.0f,max(1.0f,3.0f,4.0f)); assertEq(4.0d,max(1.0d,3.0d,4.0d)); } |
ArrayMath { public static int min(int a, int b) { return (a<=b)?a:b; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x); s... | @Test public void testMin() { assertEq(1,min(3,1,4,2)); assertEq(1L,min(3L,1L,4L,2L)); assertEq(1.0f,min(3.0f,1.0f,4.0f,2.0f)); assertEq(1.0d,min(3.0d,1.0d,4.0d,2.0d)); assertEq(1,min(3,1,4)); assertEq(1L,min(3L,1L,4L)); assertEq(1.0f,min(3.0f,1.0f,4.0f)); assertEq(1.0d,min(3.0d,1.0d,4.0d)); } |
ArrayMath { public static double cbrt(double a) { return Math.cbrt(a); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x);... | @Test public void testCubicRoot() { assertEq(2.0, cbrt(8.0)); assertEq(2.0f, cbrt(8.0f)); } |
ArrayMath { public static double hypot(double x, double y) { return Math.hypot(x,y); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double a... | @Test public void testHypotenuse() { assertEq(5.0, hypot(3.0, 4.0)); assertEq(5.0f, hypot(3.0f, 4.0f)); } |
ArrayMath { public static double expm1(double x) { return Math.expm1(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x... | @Test public void testExponentialMinusOne() { assertEq(22025.46579480, expm1(10.0)); assertEq(22025.46579480f, expm1(10.0f)); } |
ArrayMath { public static double log1p(double x) { return Math.log1p(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x... | @Test public void testLnPlusOne() { assertEq(2.39789527279837 , log1p(10.0 )); assertEq(2.39789527279837f, log1p(10.0f)); } |
ArrayMath { public static float log10(float x) { return (float)Math.log10(x); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(dou... | @Test public void testLog10() { float fi = 1.0f; double di = 1.0; for (int i=1; i<=10; ++i) { fi *= 10.0f; di *= 10.0; assertEq((float)i, log10(fi)); assertEq((double)i, log10(di)); } } |
ArrayMath { public static double ulp(double d) { return Math.ulp(d); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float x); static double asin(double x); s... | @Test public void testUlp() { assertEq(FLT_EPSILON, ulp(1.2345f)); assertEq(DBL_EPSILON, ulp(1.2345)); } |
ArrayMath { public static double IEEEremainder(double f1, double f2) { return Math.IEEEremainder(f1,f2); } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static float asin(float... | @Test public void testIEEERemainder() { assertEq(-1.0d, IEEEremainder(3.0d,2.0d)); assertEq(-1.0f, IEEEremainder(3.0f,2.0f)); } |
ArrayMath { public static byte[] rampbyte(byte ra, byte rb1, int n1) { byte[] rx = new byte[n1]; ramp(ra,rb1,rx); return rx; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); sta... | @Test public void testRampBytes() { int n1 = 7; int n2 = 5; int n3 = 3; byte f = (byte)0; byte r1 = (byte)1; byte r2 = (byte)2; byte[] arr1 = rampbyte(f,r1,n3); byte[][] arr2 = rampbyte(f,r1,r2,n3,n2); byte[][][] arr3 = rampbyte(f,r1,r2,r1,n3,n2,n1); for (int i3=0; i3<n3; ++i3) { for (int i2=0; i2<n2; ++i2) { for (int ... |
ArgsParser { public static int toInt(String s) throws OptionException { try { return Integer.parseInt(s); } catch (NumberFormatException e) { throw new OptionException("the value "+s+" is not a valid int"); } } ArgsParser(String[] args, String shortOpts); ArgsParser(String[] args, String shortOpts, String[] longOpts);... | @Test(expectedExceptions = ArgsParser.OptionException.class) public void testIntConverterShouldThrowException() throws Exception { ArgsParser.toInt("1986"); ArgsParser.toInt("Foo"); } |
ArrayMath { public static short[] rampshort(short ra, short rb1, int n1) { short[] rx = new short[n1]; ramp(ra,rb1,rx); return rx; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x... | @Test public void testRampShorts() { int n1 = 7; int n2 = 5; int n3 = 3; short f = 0; short r1 = 1; short r2 = 2; short[] arr1 = rampshort(f,r1,n3); short[][] arr2 = rampshort(f,r1,r2,n3,n2); short[][][] arr3 = rampshort(f,r1,r2,r1,n3,n2,n1); for (int i3=0; i3<n3; ++i3) { for (int i2 = 0; i2 < n2; ++i2) { for (int i1 =... |
ArrayMath { public static int[] rampint(int ra, int rb1, int n1) { int[] rx = new int[n1]; ramp(ra,rb1,rx); return rx; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); static fl... | @Test public void testRampInts() { int n1 = 7; int n2 = 5; int n3 = 3; int f = 0; int r1 = 1; int r2 = 2; int[] arr1 = rampint(f,r1,n3); int[][] arr2 = rampint(f,r1,r2,n3,n2); int[][][] arr3 = rampint(f,r1,r2,r1,n3,n2,n1); for (int i3=0; i3<n3; ++i3) { for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++i1) { assertE... |
ArrayMath { public static long[] ramplong(long ra, long rb1, int n1) { long[] rx = new long[n1]; ramp(ra,rb1,rx); return rx; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(double x); sta... | @Test public void testRampLongs() { int n1 = 7; int n2 = 5; int n3 = 3; long f = 0L; long r1 = 1L; long r2 = 2L; long[] arr1 = ramplong(f,r1,n3); long[][] arr2 = ramplong(f,r1,r2,n3,n2); long[][][] arr3 = ramplong(f,r1,r2,r1,n3,n2,n1); for (int i3=0; i3<n3; ++i3) { for (int i2=0; i2<n2; ++i2) { for (int i1=0; i1<n1; ++... |
ArrayMath { public static double[] rampdouble(double ra, double rb1, int n1) { double[] rx = new double[n1]; ramp(ra,rb1,rx); return rx; } private ArrayMath(); static float sin(float x); static double sin(double x); static float cos(float x); static double cos(double x); static float tan(float x); static double tan(do... | @Test public void testRampDoubles() { int n1 = 7; int n2 = 5; int n3 = 3; double f = 0.0d; double r1 = 1.0d; double r2 = 2.0d; double[] arr1 = rampdouble(f,r1,n3); double[][] arr2 = rampdouble(f,r1,r2,n3,n2); double[][][] arr3 = rampdouble(f,r1,r2,r1,n3,n2,n1); for (int i3=0; i3<n3; ++i3) { for (int i2=0; i2<n2; ++i2) ... |
BrentMinFinder { public double findMin(double a, double b, double tol) { double x = a+GSI*(b-a); double v = x; double w = x; double fx = f(x); double fv = fx; double fw = fx; double d = 0.0; double e = 0.0; for (double xm = 0.5*(a+b), tol1 = EPS*abs(x)+tol/3.0, tol2 = 2.0*tol1; abs(x-xm) > tol2-0.5*(b-a); xm = 0.5*(a+b... | @Test public void testSimple() { BrentMinFinder bmf = new BrentMinFinder(new BrentMinFinder.Function() { public double evaluate(double x) { return x*(x*x-2.0)-5.0; } }); double xmin = bmf.findMin(0.0,1.0,1.0e-5); trace("xmin="+xmin); assertEquals(0.81650,xmin,0.00001); }
@Test public void testMinFinder() { MinFunc1 f1 ... |
ScalarSolver { public double solve(final double scalarMin, final double scalarMax, final double okError, final double okFraction, final int numberIterations, Monitor monitor) { if (monitor == null) { monitor = Monitor.NULL_MONITOR; } monitor.report(0.0); int nter = numberIterations; if (nter < 6) { nter = 6; } final do... | @Test public void testLinearObjFunc() throws Exception { final double answer = 1./3.; final int[] calls = new int[]{0}; ScalarSolver solver = new ScalarSolver(new Function() { public double function(double scalar) { ++calls[0]; return Math.abs(scalar - answer); } }); double xmin = solver.solve(0., 1., 0.001, 0.001, 20,... |
ArgsParser { public static long toLong(String s) throws OptionException { try { return Long.parseLong(s); } catch (NumberFormatException e) { throw new OptionException("the value "+s+" is not a valid long"); } } ArgsParser(String[] args, String shortOpts); ArgsParser(String[] args, String shortOpts, String[] longOpts)... | @Test(expectedExceptions = ArgsParser.OptionException.class) public void testLongConverterShouldThrowException() throws Exception { ArgsParser.toLong("1986"); ArgsParser.toLong("Foo"); } |
BrentZeroFinder { public double findZero(double a, double b, double tol) { double fa = _f.evaluate(a); double fb = _f.evaluate(b); return findZero(a,fa,b,fb,tol); } BrentZeroFinder(Function f); double f(double x); double findZero(double a, double b, double tol); double findZero(
double a, double fa, double b, doubl... | @Test public void testForsythe() { ZeroFunc1 f1 = new ZeroFunc1(); f1.findZero(2.0,3.0); ZeroFunc2 f2 = new ZeroFunc2(); f2.findZero(-1.0,3.0); ZeroFunc3 f3 = new ZeroFunc3(); f3.findZero(-1.0,3.0); } |
QuadraticSolver { public Vect solve(final int numberIterations, Monitor monitor) { if (monitor == null) { monitor = Monitor.NULL_MONITOR; } monitor.report(0.0); VectConst b = _quadratic.getB(); monitor.report(1.0 / (numberIterations + 2.0)); final double bb = b.dot(b); checkNaN(bb); if (Almost.FLOAT.zero(bb)) { LOG.fin... | @Test public void testQS() { Quadratic q = new Quadratic() { public void multiplyHessian(Vect x) { double[] data = ((ArrayVect1)x).getData(); double[] newData = new double[data.length]; newData[0] = 2.*data[0] + 4.*data[1]; newData[1] = 4.*data[0] + 11.*data[1]; data[0] = newData[0]; data[1] = newData[1]; } public void... |
BoundingBoxTree { public Node getRoot() { return _root; } BoundingBoxTree(int minSize, float[] xyz); BoundingBoxTree(int minSize, float[] x, float[] y, float[] z); Node getRoot(); } | @Test public void testRandom() { int minSize = 10; int n = 10000; float[] x = randfloat(n); float[] y = randfloat(n); float[] z = randfloat(n); BoundingBoxTree bbt = new BoundingBoxTree(minSize,x,y,z); BoundingBoxTree.Node root = bbt.getRoot(); test(root,minSize,x,y,z); } |
DMatrixChd { public double det() { return _det; } DMatrixChd(DMatrix a); boolean isPositiveDefinite(); DMatrix getL(); double det(); DMatrix solve(DMatrix b); } | @Test public void testSimple() { DMatrix a = new DMatrix(new double[][]{ {1.0, 1.0}, {1.0, 4.0}, }); test(a); DMatrixChd chd = new DMatrixChd(a); assertEqualFuzzy(3.0,chd.det()); } |
DMatrixLud { public double det() { Check.argument(_m==_n,"A is square"); return _det; } DMatrixLud(DMatrix a); boolean isSingular(); DMatrix getL(); DMatrix getU(); DMatrix getP(); int[] getPivotIndices(); double det(); DMatrix solve(DMatrix b); } | @Test public void testSimple() { DMatrix a = new DMatrix(new double[][]{ {0.0, 2.0}, {3.0, 4.0}, }); test(a); DMatrixLud lud = new DMatrixLud(a); assertEqualFuzzy(-6.0,lud.det()); } |
DMatrixQrd { public boolean isFullRank() { for (int j=0; j<_n; ++j) { if (_qr[j+j*_m]==0.0) return false; } return true; } DMatrixQrd(DMatrix a); boolean isFullRank(); DMatrix getQ(); DMatrix getR(); DMatrix solve(DMatrix b); } | @Test public void testRankDeficient() { DMatrix a = new DMatrix(new double[][]{ {0.0, 0.0}, {3.0, 4.0}, }); DMatrixQrd qrd = new DMatrixQrd(a); assertFalse(qrd.isFullRank()); } |
DMatrixSvd { public double cond() { return _s[0]/_s[_mn-1]; } DMatrixSvd(DMatrix a); DMatrix getU(); DMatrix getS(); double[] getSingularValues(); DMatrix getV(); DMatrix getVTranspose(); double norm2(); double cond(); int rank(); } | @Test public void testCond() { DMatrix a = new DMatrix(new double[][]{ {1.0, 3.0}, {7.0, 9.0}, }); int m = a.getM(); int n = a.getN(); DMatrixSvd svd = new DMatrixSvd(a); double[] s = svd.getSingularValues(); double smax = max(s); assertEqualExact(s[0],smax); double smin = min(s); assertEqualExact(s[min(m,n)-1],smin); ... |
ArgsParser { public ArgsParser(String[] args, String shortOpts) throws OptionException { _args = args; _shortOpts = shortOpts; _longOpts = new String[0]; init(); } ArgsParser(String[] args, String shortOpts); ArgsParser(String[] args, String shortOpts, String[] longOpts); String[] getOptions(); String[] getValues(); S... | @Test public void testArgsParser() { String[][] args = { {"-a3.14","-b","foo"}, {"-a","3.14","-b","foo"}, {"--alpha","3.14","--beta","foo"}, {"--a=3.14","--b","foo"}, {"--a=3.14","--b","foo"}, }; for (String[] arg:args) { float a = 0.0f; boolean b = false; try { String shortOpts = "ha:b"; String[] longOpts = {"help","a... |
GeneralUtilities extends SpagoBIUtilities { public static Map<String, ParamDefaultValue> getParamsDefaultValuesUseAlsoDB(IDataSet dataSet) { Map<String, ParamDefaultValue> res = DataSetUtilities.getParamsDefaultValues(dataSet); if (res != null) { return res; } logger.warn("No params default values found on dataSet. I t... | @Test public void testGetParamsDefaultValuesEmptyNoDSLabel() { IDataSet dummy = new MockDataSet(); Map<String, ?> dvs = GeneralUtilities.getParamsDefaultValuesUseAlsoDB(dummy); Assert.assertNull(dvs); }
@Test public void testGetParamsDefaultValuesParamsStringNoDSLabel() { IDataSet dummy = new MockDataSet(); dummy.setPa... |
DataSetParametersList { public static DataSetParametersList fromXML(String dataDefinition) throws SourceBeanException { return new DataSetParametersList(dataDefinition); } DataSetParametersList(); DataSetParametersList(String dataDefinition); void loadFromXML(String dataDefinition); String toXML(); String getDataSetRe... | @Test public void testFromXML() throws SourceBeanException { DataSetParametersList fromXML = DataSetParametersList.fromXML(XML); checkParams(fromXML); } |
StringUtilities { public static String[] getSubstringsBetween(String values, String delimiter) { try { ArrayList<String> arrayList = new ArrayList<>(); int start = values.indexOf(delimiter); int delimiterLength = delimiter.length(); while (start > -1) { int end = values.indexOf(delimiter, start + delimiterLength); arra... | @Test public void getSubstringsBetweenTest() { String delimiter = "'"; String values = "('1')"; String[] result = StringUtilities.getSubstringsBetween(values, delimiter); assertEquals(1, result.length); assertEquals("1", result[0]); values = "('2')"; result = StringUtilities.getSubstringsBetween(values, delimiter); ass... |
StringUtilities { public static String[] splitBetween(String values, String prefix, String delimiter, String suffix) { int prefixIndex = values.indexOf(prefix); int suffixIndex = values.lastIndexOf(suffix); if (prefixIndex > -1 && suffixIndex > -1) { int prefixLength = prefix.length(); String[] returnedValues = values.... | @Test public void splitBetweenTest() { String prefix = "'"; String delimiter = "','"; String suffix = "'"; String values = "('D'rink','Fo'od')"; String[] result = StringUtilities.splitBetween(values, prefix, delimiter, suffix); assertEquals(2, result.length); assertEquals("D'rink", result[0]); assertEquals("Fo'od", res... |
ParametersDecoder { public boolean isMultiValues(String value) { return value.trim().matches(multiValueRegex); } ParametersDecoder(); ParametersDecoder(String openBlockMarker, String closeBlockMarker); String getCloseBlockMarker(); void setCloseBlockMarker(String closeBlockMarker); String getOpenBlockMarker(); void se... | @Test public void testIsMultiValue() { ParametersDecoder decoder = new ParametersDecoder(); String value = "{;{American;Colony;Ebony;Johnson;Urban}STRING}"; boolean isMultiValue = decoder.isMultiValues(value); assertTrue(isMultiValue); String json = "{name: {a : 4, b : 4}}"; isMultiValue = decoder.isMultiValues(json); ... |
SimpleRestClient { protected Response executeGetService(Map<String, Object> parameters, String serviceUrl, String userId) throws Exception { return executeService(parameters, serviceUrl, userId, RequestTypeEnum.GET, null, null); } SimpleRestClient(String hmacKey); SimpleRestClient(); boolean isAddServerUrl(); void set... | @Test public void testExecuteGetService() throws Exception { SimpleRestClient client = getSimpleRestClient(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("a", "b"); parameters.put("c", "d"); Response resp = client.executeGetService(parameters, "http: Assert.assertEquals(200, resp.getS... |
SimpleRestClient { protected Response executePostService(Map<String, Object> parameters, String serviceUrl, String userId, String mediaType, Object data) throws Exception { return executeService(parameters, serviceUrl, userId, RequestTypeEnum.POST, mediaType, data); } SimpleRestClient(String hmacKey); SimpleRestClient... | @Test public void testExecutePostService() throws Exception { SimpleRestClient client = getSimpleRestClient(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("a", "b"); parameters.put("c", "d"); Response resp = client.executePostService(parameters, "http: Assert.assertEquals(200, resp.ge... |
HMACFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new IllegalArgumentException("request not instance of HttpServletRequest"); } HttpServletRequest... | @Test public void testDoFilter() throws IOException, NoSuchAlgorithmException, HMACSecurityException { Map<String, String> headers = new HashMap<String, String>(); String token = "" + System.currentTimeMillis(); headers.put(HMACUtils.HMAC_TOKEN_HEADER, token); headers.put(HMACUtils.HMAC_SIGNATURE_HEADER, getSignature("... |
RealtimeEvaluationStrategy extends CachedEvaluationStrategy { @Override protected DatasetEvaluationStrategyType getEvaluationStrategy() { return DatasetEvaluationStrategyType.REALTIME; } RealtimeEvaluationStrategy(UserProfile userProfile, IDataSet dataSet, ICache cache); } | @Test public void shouldReturnRealtimeStrategyType() { RealtimeEvaluationStrategy strategy = (RealtimeEvaluationStrategy) DatasetEvaluationStrategyFactory.get(DatasetEvaluationStrategyType.REALTIME, new MockDataSet(), new UserProfile()); assertThat(strategy.getEvaluationStrategy(), is(DatasetEvaluationStrategyType.REAL... |
DatasetEvaluationStrategyFactory { public static IDatasetEvaluationStrategy get(DatasetEvaluationStrategyType strategyType, IDataSet dataSet, UserProfile userProfile) { Assert.assertNotNull(strategyType, "Strategy type cannot be null"); Assert.assertNotNull(dataSet, "Dataset cannot be null"); switch (strategyType) { ca... | @Test public void shouldGetPersistedStrategy() { IDatasetEvaluationStrategy strategy = DatasetEvaluationStrategyFactory.get(DatasetEvaluationStrategyType.PERSISTED, dataSet, new UserProfile()); Assert.assertThat(strategy, instanceOf(PersistedEvaluationStrategy.class)); }
@Test public void shouldGetFlatStrategy() { IDat... |
PersistedEvaluationStrategy extends AbstractJdbcEvaluationStrategy { @Override protected String getTableName() { return dataSet.getPersistTableName(); } PersistedEvaluationStrategy(IDataSet dataSet); } | @Test public void shouldUsePersistedTableName() { final String TABLE_NAME = "PersistedTable"; MockDataSet dataSet = new MockDataSet(); dataSet.setPersistTableName(TABLE_NAME); PersistedEvaluationStrategy strategy = (PersistedEvaluationStrategy) DatasetEvaluationStrategyFactory.get(DatasetEvaluationStrategyType.PERSISTE... |
PersistedEvaluationStrategy extends AbstractJdbcEvaluationStrategy { @Override protected IDataSource getDataSource() { return dataSet.getDataSourceForWriting(); } PersistedEvaluationStrategy(IDataSet dataSet); } | @Test public void shouldUseDatasourceForWriting() { final String DATASOURCE_LABEL = "DatasourceForWriting"; MockDataSet dataSet = new MockDataSet(); IDataSource dataSource = DataSourceFactory.getDataSource(); dataSource.setLabel(DATASOURCE_LABEL); dataSet.setDataSourceForWriting(dataSource); PersistedEvaluationStrategy... |
PersistedEvaluationStrategy extends AbstractJdbcEvaluationStrategy { @Override protected Date getDate() { Date toReturn = null; Trigger trigger = loadTrigger(); Date previousFireTime = null; if (trigger != null) { previousFireTime = trigger.getPreviousFireTime(); } if (previousFireTime != null) { toReturn = previousFir... | @Test public void shouldUsePreviousFireTimeToSetDataStoreDate() { final Date now = new Date(); new MockUp<PersistedEvaluationStrategy>() { @Mock private Trigger loadTrigger() { Trigger trigger = new Trigger(); trigger.setPreviousFireTime(now); return trigger; } }; PersistedEvaluationStrategy strategy = (PersistedEvalua... |
CachedEvaluationStrategy extends AbstractEvaluationStrategy { protected DatasetEvaluationStrategyType getEvaluationStrategy() { return DatasetEvaluationStrategyType.CACHED; } CachedEvaluationStrategy(UserProfile userProfile, IDataSet dataSet, ICache cache); } | @Test public void shouldReturnCachedStrategyType() { CachedEvaluationStrategy strategy = (CachedEvaluationStrategy) DatasetEvaluationStrategyFactory.get(DatasetEvaluationStrategyType.CACHED, new MockDataSet(), new UserProfile()); assertThat(strategy.getEvaluationStrategy(), is(DatasetEvaluationStrategyType.CACHED)); } |
ManageDatasets extends AbstractSpagoBIAction { static String getSingleValue(String value, String type) { String toReturn = ""; value = value.trim(); if (type.equalsIgnoreCase(DataSetUtilities.STRING_TYPE)) { if (!(value.startsWith("'") && value.endsWith("'"))) { toReturn = "'" + value + "'"; } else { toReturn = value; ... | @Test public void testGetSingleValue() { String[] types = new String[] { DataSetUtilities.GENERIC_TYPE, DataSetUtilities.NUMBER_TYPE, DataSetUtilities.RAW_TYPE, DataSetUtilities.STRING_TYPE }; String[] values = new String[] { "", "'", "''", "0", "'0", "0'", "'0'", "17", "abc", "'qcd'", "'qcd", "qcd'" }; Map<String, Map... |
LabeledEdge extends DefaultEdge { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; LabeledEdge other = (LabeledEdge) obj; if (label == null) { if (other.label != null) return false; } else if (!label.equals(other.l... | @Test public void testEquals() { assertEquals(new LabeledEdge<String>("x", "y", "label"), new LabeledEdge<String>("x", "y", "label")); assertEquals(new LabeledEdge<String>("x", "y", "label"), new LabeledEdge<String>("y", "x", "label")); assertNotEquals(new LabeledEdge<String>("x", "y", "label"), new LabeledEdge<String>... |
EdgeGroup { @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof EdgeGroup)) return false; EdgeGroup other = (EdgeGroup) obj; if (orderedEdgeNames == null) { if (other.orderedEdgeNames != null) return false; } else if (!orderedEdgeNames.equals(o... | @Test public void testEquals() { assertEquals(eg1, eg1); assertEquals(eg1, eg2); assertNotEquals(eg1, eg3); } |
EdgeGroup { public String getOrderedEdgeNames() { return orderedEdgeNames; } EdgeGroup(Set<LabeledEdge<String>> edges); Set<String> getEdgeNames(); String getOrderedEdgeNames(); Set<Tuple> getValues(); void addValues(Set<Tuple> values); void addValue(Tuple value); boolean isResolved(); void resolve(); void unresolve();... | @Test public void testGetColumnNames() { assertEquals(eg1.getOrderedEdgeNames(), eg1.getOrderedEdgeNames()); assertEquals(eg1.getOrderedEdgeNames(), eg4.getOrderedEdgeNames()); } |
PersistedHDFSManager implements IPersistedManager { public Object persistDataStore(IDataStore dataStore, String fileName, String folderName) { FSDataOutputStream fsOS = openHdfsFile(fileName, folderName); IMetaData mt = dataStore.getMetaData(); int nFields = mt.getFieldCount(); try { logger.debug("Starting writing the ... | @Test public void testPersistDataStore() { IDataStore dataStore = Mockito.mock(IDataStore.class); IMetaData metaData = Mockito.mock(IMetaData.class); IRecord record = Mockito.mock(IRecord.class); IField fieldInt = Mockito.mock(IField.class); IField fieldStr = Mockito.mock(IField.class); Mockito.when(dataStore.getMetaDa... |
DataSetUtilities { public static Map<String, ParamDefaultValue> getParamsDefaultValuesUseAlsoService(IDataSet dataSet, String user, HttpSession session) { Helper.checkNotNull(dataSet, "dataSet"); Helper.checkNotNull(session, "session"); Helper.checkNotNullNotTrimNotEmpty(user, "user"); Map<String, ParamDefaultValue> re... | @Ignore @Test public void testGetParamsDefaultValuesUseAlsoService() throws Exception { UtilitiesForTest.setUpTestJNDI(); EnginConf.setTestconfigInputstream(new FileInputStream("resources-test/engine-config.xml")); UtilitiesForTest.writeSessionOfWebApp(); HttpSession session = UtilitiesForTest.getSession(); MockDataSet... |
DataSetUtilities { @SuppressWarnings("unchecked") public static Map<String, ParamDefaultValue> getParamsDefaultValues(IDataSet dataSet) { Helper.checkNotNull(dataSet, "dataSet"); try { String params = dataSet.getParameters(); if (params == null || params.isEmpty()) { return null; } Map<String, ParamDefaultValue> res = ... | @Test public void testGetParamsDefaultValues() { IDataSet dataSet = new MockDataSet(); dataSet.setParameters(DataSetParametersListTest.XML); Map<String, ParamDefaultValue> pdvs = DataSetUtilities.getParamsDefaultValues(dataSet); checkParams(pdvs); } |
DataSetUtilities { @SuppressWarnings({ "rawtypes", "unchecked" }) public static void fillDefaultValues(IDataSet dataSet, Map parameters) { if (disableDefaultParams) { return; } Helper.checkNotNull(dataSet, "dataset"); if (parameters == null) { return; } int oldSize = parameters.size(); Map<String, ParamDefaultValue> de... | @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testFillDefaultValues() { IDataSet dataSet = new MockDataSet(); dataSet.setParameters(DataSetParametersListTest.XML); Map parameters = new HashMap<String, String>(); parameters.put(DataSetParametersListTest.FIRST_PARAM, "a"); parameters.put(DataSetParamet... |
DataSetParametersList { public void loadFromXML(String dataDefinition) throws SourceBeanException { logger.debug("IN"); dataDefinition.trim(); InputSource stream = new InputSource(new StringReader(dataDefinition)); SourceBean source = SourceBean.fromXMLStream(stream); if (!source.getName().equals("PARAMETERSLIST")) { S... | @Test public void testLoadFromXML() throws SourceBeanException { DataSetParametersList dspl = new DataSetParametersList(); dspl.loadFromXML(XML); checkParams(dspl); } |
DataSetParametersList { public String toXML() { logger.debug("IN"); String lovXML = ""; lovXML += "<PARAMETERSLIST>"; lovXML += "<ROWS>"; DataSetParameterItem lov = null; Iterator iter = items.iterator(); while (iter.hasNext()) { lov = (DataSetParameterItem) iter.next(); String name = lov.getName(); String type = lov.g... | @Test public void testToXML() { DataSetParametersList dspl = new DataSetParametersList(); dspl.add(FIRST_PARAM, "string"); dspl.add(SECOND_PARAM, "number"); String xml = dspl.toXML(); assertEquals( "<PARAMETERSLIST><ROWS><ROW NAME=\"firstParam\" TYPE=\"string\" DEFAULT_VALUE=\"\" /><ROW NAME=\"secondParam\" TYPE=\"numb... |
ExceptionUtilities { public static String getStackTraceAsString( Exception aException ){ String vStackTrace = "\t" + aException.toString() + "\n"; for( StackTraceElement vElement : aException.getStackTrace() ){ vStackTrace += "\t\t" + vElement.toString() + "\n"; } return vStackTrace; } static String getStackTraceAsStr... | @Test public void testGetStackTraceAsString() { Exception mockException = mock(Exception.class); when(mockException.toString()).thenReturn("Mocked Exception"); when(mockException.getStackTrace()).thenReturn(new StackTraceElement[]{ new StackTraceElement("String","toString()","testfile",123), new StackTraceElement("Test... |
ToServerManagement extends Thread { public static ToServerManagement getInstance() { if( ToServerManagement.sINSTANCE == null){ ToServerManagement.sINSTANCE = new ToServerManagement(); } return ToServerManagement.sINSTANCE; } ToServerManagement(); static ToServerManagement getInstance(); void close(); void resumeManage... | @Test public void testGetInstance() { ToServerManagement vSaveToCompare = ToServerManagement.getInstance(); assertThat(vSaveToCompare).isInstanceOf(ToServerManagement.class); assertThat(vSaveToCompare).isEqualTo(ToServerManagement.getInstance()); } |
ToServerManagement extends Thread { public void stopManagement(){ synchronized (this) { mManageMessagesToServer = false; } if( isAlive()){ resumeManagement(); while(isAlive()){ try { Thread.sleep( 10 ); } catch ( Exception vException ) { Core.getLogger().error( "Error stopping ToServerManagement.", vException ); } } Co... | @Test public void testStopManagementWhenNotAlive() { assertThat(mSUT.isAlive()).isFalse(); mSUT.stopManagement(); assertThat(mSUT.isAlive()).isFalse(); verify(mLoggerMock, never()).info("ToServerManagement stopped."); } |
ToServerManagement extends Thread { public boolean isSendingMessages(){ return isAlive() && (System.currentTimeMillis() - mLastSendMessage.get() ) < 100; } ToServerManagement(); static ToServerManagement getInstance(); void close(); void resumeManagement(); boolean isSuspended(); void suspendManagement(); @Override voi... | @Test public void testIsSendingMessagesWhenNotAlive() { assertThat(mSUT.isAlive()).isFalse(); assertThat(mSUT.isSendingMessages()).isFalse(); } |
ToServerManagement extends Thread { public void startManagement(){ if( Core.getInstance().getServerConnection() == null ) { throw new NullPointerException( "NetworkCommunication cannot be NULL when starting ToServerManagement." ) ; } else if ( isAlive() ){ throw new IllegalThreadStateException( "ToServerManagement can ... | @Test public void testSendMessagesWithAI() throws Exception { when(mCoreMock.getServerConnection()).thenReturn( mNetworkCommunicationMock ); when(mCoreMock.getAI()).thenReturn( mArtificialIntelligenceMock ); when(mArtificialIntelligenceMock.getAction()).thenAnswer(new Answer<Action>() { @Override public Action answer(I... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.