Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.PermutationEncoding-3.3/PermutationEqualityComparerTest.cs @ 8012

Last change on this file since 8012 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Encodings.PermutationEncoding;
23using Microsoft.VisualStudio.TestTools.UnitTesting;
24
25namespace HeuristicLab.Encodings.PermutationEncoding_33.Tests {
26  [TestClass]
27  public class PermutationEqualityComparerTest {
28    [TestMethod]
29    public void TestPermutationEqualityComparer() {
30      PermutationEqualityComparer comparer = new PermutationEqualityComparer();
31      Permutation p = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 3, 2, 0, 1, 4 });
32      Permutation q = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 1, 0, 2, 3, 4 });
33      Assert.IsTrue(comparer.Equals(p, q));
34      Assert.IsTrue(comparer.GetHashCode(p) == comparer.GetHashCode(q));
35      Permutation p2 = new Permutation(PermutationTypes.RelativeDirected, new int[] { 2, 3, 4, 1, 0 });
36      Permutation q2 = new Permutation(PermutationTypes.RelativeDirected, new int[] { 1, 0, 2, 3, 4 });
37      Assert.IsTrue(comparer.Equals(p2, q2));
38      Assert.IsTrue(comparer.GetHashCode(p2) == comparer.GetHashCode(q2));
39
40      Assert.IsFalse(comparer.Equals(p, q2));
41      Assert.IsFalse(comparer.Equals(p2, q));
42
43      Permutation p3 = new Permutation(PermutationTypes.Absolute, new int[] { 2, 3, 0, 4, 1 });
44      Permutation q3 = new Permutation(PermutationTypes.Absolute, new int[] { 2, 3, 0, 4, 1 });
45      Assert.IsTrue(comparer.Equals(p3, q3));
46      Assert.IsTrue(comparer.GetHashCode(p3) == comparer.GetHashCode(q3));
47
48      Assert.IsFalse(comparer.Equals(p3, q));
49      Assert.IsFalse(comparer.Equals(p2, q3));
50
51      Permutation p4 = new Permutation(PermutationTypes.RelativeUndirected, new int[] { 3, 2, 0, 1, 4, 5 });
52      Assert.IsFalse(comparer.Equals(p, p4));
53      Assert.IsFalse(comparer.Equals(p4, q));
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.