/** * This test validates that equality is independent of the amount of used indices. */ @Test public void testMaxByComparisonMultiple() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 1, 2, 3, 4}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(smaller, bigger)); Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * This test validates whether the order of tuples has any impact on the outcome and if the bigger tuple is returned. */ @Test public void testMaxByComparison() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(smaller, bigger)); Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * This test cases checks when two tuples only differ in one value. */ @Test public void testMaxByComparisonSpecialCase2() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 2, 1, 4, 3}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(specialCaseBigger, bigger)); Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, specialCaseBigger)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * Checks whether reduce does behave as expected if both values are the same object. */ @Test public void testMaxByComparisonMustReturnATuple() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0}); try { Assert.assertSame("SelectByMax must return bigger tuple", bigger, maxByTuple.reduce(bigger, bigger)); Assert.assertSame("SelectByMax must return smaller tuple", smaller, maxByTuple.reduce(smaller, smaller)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }
/** * This test cases checks when two tuples only differ in one value, but this value is not * in the fields list. In that case it should be seen as equal and then the first given tuple (value1) should be returned by reduce(). */ @Test public void testMaxByComparisonSpecialCase1() { SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>> maxByTuple = new SelectByMaxFunction<Tuple5<Integer, Long, String, Long, Integer>>(tupleTypeInfo, new int[] {0, 3}); try { Assert.assertSame("SelectByMax must return the first given tuple", specialCaseBigger, maxByTuple.reduce(specialCaseBigger, bigger)); Assert.assertSame("SelectByMax must return the first given tuple", bigger, maxByTuple.reduce(bigger, specialCaseBigger)); } catch (Exception e) { Assert.fail("No exception should be thrown while comparing both tuples"); } }