View Javadoc

1   /*
2    * DaCapo Benchmark Maven Plugin
3    * Copyright (C) 2010 Technische Universität Darmstadt
4    * info@scalabench.org
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.scalabench.plugins.dacapo.util;
19  
20  import static java.lang.Math.signum;
21  import static org.junit.Assert.assertTrue;
22  
23  import java.util.Comparator;
24  
25  import org.junit.Test;
26  
27  public class SizeNameComparatorTest {
28      
29      /**
30       * Ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y.
31       * 
32       * @see java.util.Comparator#compare(Object, Object)
33       */
34      @Test
35      public void testSymmetryAndReflexivity() {
36          for (String x : commonSizeNames)
37              for (String y : commonSizeNames)
38                  assertTrue(signum(cmp.compare(x, y)) == - signum(cmp.compare(y, x)));
39      }
40      
41      /**
42       * Ensure that the relation is transitive: ((compare(x, y) > 0) && (compare(y, z) > 0)) implies compare(x, z) > 0.
43       * 
44       * @see java.util.Comparator#compare(Object, Object)
45       */
46      @Test
47      public void testTransitivity() {
48          for (String x : commonSizeNames)
49              for (String y : commonSizeNames)
50                  for (String z : commonSizeNames)
51                      if (cmp.compare(x, y) > 0 && cmp.compare(y, z) > 0)
52                          assertTrue(cmp.compare(x, z) > 0);
53      }
54      
55      private final Comparator<String> cmp = new SizeNameComparator();
56      
57      private static String[] commonSizeNames = new String[] {
58          "tiny",
59          "small",
60          "default",
61          "large",
62          "huge",
63          "gargantuan",
64          "colossal"
65      };
66  }