Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15192


Ignore:
Timestamp:
07/11/17 11:31:07 (7 years ago)
Author:
abeham
Message:

#2803: improved shuffle test a little

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Tests/HeuristicLab.IGraph/IGraphWrappersVectorTest.cs

    r15191 r15192  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Linq;
     25using HeuristicLab.Encodings.RealVectorEncoding;
    2326using HeuristicLab.IGraph.Wrappers;
    2427using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    104107    [TestProperty("Time", "short")]
    105108    public void IGraphWrappersVectorShuffleTest() {
    106       var different = 0;
     109      var different = new HashSet<RealVector>(new RealVectorEqualityComparer());
    107110      for (var i = 0; i < 100; i++) {
    108111        using (var vector = new Vector(5)) {
     
    113116          vector.Shuffle();
    114117          var result = vector.ToArray();
    115           if (!result.SequenceEqual(new double[] { 4, 4, 3, 1.5, -0.5 }))
    116             different++;
     118          different.Add(new RealVector(result));
    117119          Assert.AreEqual(2, result.Count(x => x == 4));
    118120          Assert.AreEqual(1, result.Count(x => x == 3));
     
    122124      }
    123125      // There should be reasonable low probability that all 100 shuffles result in exactly the same vector
    124       Assert.IsTrue(different > 0);
     126      Assert.IsTrue(different.Count > 1);
     127      Assert.IsTrue(different.Count <= 60); // there are a total of 60 different shuffles 5! / 2!
     128      Console.WriteLine("Shuffle produced " + different.Count + " unique vectors");
    125129    }
    126130
Note: See TracChangeset for help on using the changeset viewer.