1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * See LICENSE.txt included in this distribution for the specific 9 * language governing permissions and limitations under the License. 10 * 11 * When distributing Covered Code, include this CDDL HEADER in each 12 * file and include the License file at LICENSE.txt. 13 * If applicable, add the following below this CDDL HEADER, with the 14 * fields enclosed by brackets "[]" replaced with your own identifying 15 * information: Portions Copyright [yyyy] [name of copyright owner] 16 * 17 * CDDL HEADER END 18 */ 19 20 /* 21 * Copyright (c) 2018, Chris Fraire <cfraire@me.com>. 22 */ 23 24 package org.opengrok.indexer.search.context; 25 26 import static org.junit.Assert.assertEquals; 27 import org.junit.Test; 28 29 /** 30 * Represents a container of tests of {@link PhraseHighlightComparator}. 31 */ 32 public class PhraseHighlightComparatorTest { 33 34 private PhraseHighlight o1; 35 private PhraseHighlight o2; 36 37 @Test testEqualBoundedInstances()38 public void testEqualBoundedInstances() { 39 o1 = PhraseHighlight.create(0, 1); 40 o2 = PhraseHighlight.create(0, 1); 41 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 42 assertEquals("o1[0,1] should be == o2[0,1]", 0, result); 43 } 44 45 @Test testEqualUnboundedInstances()46 public void testEqualUnboundedInstances() { 47 o1 = PhraseHighlight.createEntire(); 48 o2 = PhraseHighlight.createEntire(); 49 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 50 assertEquals("o1[,] should be == o2[,]", 0, result); 51 } 52 53 @Test testEqualMixedBoundedInstances1()54 public void testEqualMixedBoundedInstances1() { 55 o1 = PhraseHighlight.createStarter(5); 56 o2 = PhraseHighlight.createStarter(5); 57 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 58 assertEquals("o1[5,] should be == o2[5,]", 0, result); 59 } 60 61 @Test testEqualMixedBoundedInstances2()62 public void testEqualMixedBoundedInstances2() { 63 o1 = PhraseHighlight.createEnder(5); 64 o2 = PhraseHighlight.createEnder(5); 65 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 66 assertEquals("o1[,5] should be == o2[,5]", 0, result); 67 } 68 69 @Test testDisjointInstances1()70 public void testDisjointInstances1() { 71 o1 = PhraseHighlight.create(0, 10); 72 o2 = PhraseHighlight.create(100, 110); 73 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 74 assertEquals("o1[0,10] should be < o2[100,110]", -1, result); 75 } 76 77 @Test testDisjointInstances2()78 public void testDisjointInstances2() { 79 o1 = PhraseHighlight.create(2, 3); 80 o2 = PhraseHighlight.create(0, 2); 81 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 82 assertEquals("o1[2,3] should be > o2[0,2]", 1, result); 83 } 84 85 @Test testBoundedOverlappingUnequalInstances1()86 public void testBoundedOverlappingUnequalInstances1() { 87 o1 = PhraseHighlight.create(0, 10); 88 o2 = PhraseHighlight.create(1, 3); 89 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 90 assertEquals("o1[0,10] should be < o2[1,3]", -1, result); 91 } 92 93 @Test testBoundedOverlappingUnequalInstances2()94 public void testBoundedOverlappingUnequalInstances2() { 95 o1 = PhraseHighlight.create(0, 5); 96 o2 = PhraseHighlight.create(0, 10); 97 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 98 assertEquals("o1[0,5] should be > o2[0,10]", 1, result); 99 } 100 101 @Test testBoundedOverlappingUnequalInstances3()102 public void testBoundedOverlappingUnequalInstances3() { 103 o1 = PhraseHighlight.create(5, 15); 104 o2 = PhraseHighlight.create(0, 10); 105 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 106 assertEquals("o1[5,15] should be > o2[0,10]", 1, result); 107 } 108 109 @Test testBoundedOverlappingUnequalInstances4()110 public void testBoundedOverlappingUnequalInstances4() { 111 o1 = PhraseHighlight.create(0, 10); 112 o2 = PhraseHighlight.create(5, 10); 113 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 114 assertEquals("o1[0,10] should be < o2[5,10]", -1, result); 115 } 116 117 @Test testMixedBoundedNonOverlappingInstances1()118 public void testMixedBoundedNonOverlappingInstances1() { 119 o1 = PhraseHighlight.createEnder(10); 120 o2 = PhraseHighlight.create(15, 30); 121 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 122 assertEquals("o1[,10] should be < o2[15,30]", -1, result); 123 } 124 125 @Test testMixedBoundedNonOverlappingInstances2()126 public void testMixedBoundedNonOverlappingInstances2() { 127 o1 = PhraseHighlight.createStarter(15); 128 o2 = PhraseHighlight.create(0, 10); 129 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 130 assertEquals("o1[15,] should be > o2[0,10]", 1, result); 131 } 132 133 @Test testMixedBoundedOverlappingInstances1()134 public void testMixedBoundedOverlappingInstances1() { 135 o1 = PhraseHighlight.createEnder(20); 136 o2 = PhraseHighlight.create(15, 30); 137 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 138 assertEquals("o1[,20] should be < o2[15,30]", -1, result); 139 } 140 141 @Test testMixedBoundedOverlappingInstances2()142 public void testMixedBoundedOverlappingInstances2() { 143 o1 = PhraseHighlight.createStarter(20); 144 o2 = PhraseHighlight.create(15, 30); 145 int result = PhraseHighlightComparator.INSTANCE.compare(o1, o2); 146 assertEquals("o1[20,] should be > o2[15,30]", 1, result); 147 } 148 } 149