Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10494


Ignore:
Timestamp:
02/21/14 10:27:11 (11 years ago)
Author:
gkronber
Message:

#21227: fixed failed unit tests after removal of equals / gethashcode methods in schedule encoding.

Location:
trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/DirectScheduleGTCrossoverTest.cs

    r9777 r10494  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.ScheduleEncoding.PermutationWithRepetition;
     
    4849      actual = DirectScheduleGTCrossover.Apply(random, parent1, parent2, jobData, mutProp);
    4950      Schedule expected = DirectScheduleRandomCreator.Apply(3, 3, new PWREncoding(3, 3, new TestRandom(new int[] { 0, 2, 1, 1, 0, 2, 1, 2, 0 }, null)), TestUtils.CreateJobData());
    50       Assert.IsTrue(actual.Equals(expected));
     51      Assert.IsTrue(TestUtils.ScheduleEquals(actual, expected));
    5152    }
     53
    5254  }
    5355}
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/JSMJOXCrossoverTest.cs

    r9777 r10494  
    5353      actual = JSMJOXCrossover.Apply(random, p1, p2);
    5454
    55       Assert.IsTrue(expected.Equals(actual));
     55      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, actual));
    5656    }
    5757  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/JSMSXXCrossoverTest.cs

    r9777 r10494  
    5353      actual = JSMSXXCrossover.Apply(random, p1, p2);
    5454
    55       Assert.IsTrue(expected.Equals(actual));
     55      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, actual));
    5656    }
    5757  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/JSMShiftChangeManipulatorTest.cs

    r9777 r10494  
    5151      expected.JobSequenceMatrix = jsm;
    5252
    53       Assert.IsTrue(individual.Equals(expected));
     53      Assert.IsTrue(TestUtils.JSMEncodingEquals(expected, individual));
    5454    }
    5555  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/PWRGOXCrossoverTest.cs

    r9777 r10494  
    4747      PWREncoding actual;
    4848      actual = PWRGOXCrossover.Apply(random, parent1, parent2);
    49       Assert.IsTrue(actual.Equals(expected));
     49      Assert.IsTrue(TestUtils.PRWEncodingEquals(expected, actual));
    5050    }
    5151  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/PWRPPXCrossoverTest.cs

    r9777 r10494  
    4747      PWREncoding actual;
    4848      actual = PWRPPXCrossover.Apply(random, parent1, parent2);
    49       Assert.IsTrue(actual.Equals(expected));
     49      Assert.IsTrue(TestUtils.PRWEncodingEquals(expected, actual));
    5050    }
    5151  }
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.Encodings.ScheduleEncoding-3.3/TestUtils.cs

    r9777 r10494  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Encodings.IntegerVectorEncoding;
     
    9798      return result;
    9899    }
     100    public static bool ScheduleEquals(Schedule actual, Schedule expected) {
     101      return actual.Resources.Count == expected.Resources.Count &&
     102             actual.Resources.Zip(expected.Resources, (a, e) => ResourceEquals(a, e)).All(_ => _);
     103    }
     104
     105    public static bool ResourceEquals(Resource actual, Resource expected) {
     106      return actual.Index == expected.Index &&
     107             actual.TotalDuration == expected.TotalDuration &&
     108             actual.Tasks.Count == expected.Tasks.Count &&
     109             actual.Tasks.Zip(expected.Tasks, (a, e) => TaskEquals(a, e)).All(_ => _);
     110    }
     111
     112    public static bool TaskEquals(ScheduledTask actual, ScheduledTask expected) {
     113      return
     114        actual.StartTime == expected.StartTime &&
     115        actual.EndTime == expected.EndTime &&
     116        actual.Duration == expected.Duration &&
     117        actual.ResourceNr == expected.ResourceNr &&
     118        actual.JobNr == expected.JobNr &&
     119        actual.TaskNr == expected.TaskNr;
     120    }
     121
     122    public static bool JSMEncodingEquals(JSMEncoding expected, JSMEncoding actual) {
     123      if (expected.JobSequenceMatrix.Count != actual.JobSequenceMatrix.Count)
     124        return false;
     125      for (int i = 0; i < expected.JobSequenceMatrix.Count; i++) {
     126        if (!PermutationEquals(expected.JobSequenceMatrix[i], actual.JobSequenceMatrix[i]))
     127          return false;
     128      }
     129      return true;
     130    }
     131    private static bool PermutationEquals(Permutation p1, Permutation p2) {
     132      if (p1.Length != p2.Length)
     133        return false;
     134      for (int i = 0; i < p1.Length; i++) {
     135        if (p1[i] != p2[i])
     136          return false;
     137      }
     138      return true;
     139    }
     140
     141    public static bool PRWEncodingEquals(PWREncoding expected, PWREncoding actual) {
     142      if (expected.PermutationWithRepetition.Length != actual.PermutationWithRepetition.Length)
     143        return false;
     144      for (int i = 0; i < expected.PermutationWithRepetition.Length; i++) {
     145        if (expected.PermutationWithRepetition[i] != actual.PermutationWithRepetition[i])
     146          return false;
     147      }
     148      return true;
     149    }
    99150  }
    100151}
Note: See TracChangeset for help on using the changeset viewer.