1  using System.Collections;


2  using System.Collections.Generic;


3  using System.Linq;


4  using HeuristicLab.Algorithms.DataAnalysis.Symbolic;


5  using HeuristicLab.Data;


6  using Microsoft.VisualStudio.TestTools.UnitTesting;


7 


8  namespace HeuristicLab.Tests {


9  [TestClass]


10  public class ConsecutiveSamplesEvaluatorTest {


11  [TestMethod]


12  public void GenerateRowsTest() {


13 


14  IntRange samples = new IntRange(0, 50);


15  IntRange fixedSamples = new IntRange(0, 30);


16  IEnumerable<int> rows = null;


17 


18  //test simple case


19  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 0);


20  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(30, 10)));


21  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 1);


22  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 10)));


23  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 2);


24  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(30, 10)));


25 


26  for (int i = 0; i < 10; i++) {


27  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: i);


28  var match = Enumerable.Range(30 + i % 2 * 10, 10);


29  Assert.IsTrue(rows.SequenceEqual(match));


30  }


31 


32  //test with overlap


33  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 5, iteration: 0);


34  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(30, 10)));


35  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 5, iteration: 1);


36  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(35, 10)));


37  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 5, iteration: 2);


38  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 10)));


39  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 5, iteration: 3);


40  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(45, 5).Concat(Enumerable.Range(30, 5))));


41  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 5, iteration: 4);


42  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(30, 10)));


43 


44  //test with overlap


45  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 0);


46  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(30, 10)));


47  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 1);


48  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(33, 10)));


49  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 2);


50  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(36, 10)));


51  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 3);


52  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(39, 10)));


53  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 4);


54  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(42, 8).Concat(Enumerable.Range(30, 2))));


55  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 5);


56  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(45, 5).Concat(Enumerable.Range(30, 5))));


57  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 6);


58  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(48, 2).Concat(Enumerable.Range(30, 8))));


59  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 7, iteration: 7);


60  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(31, 10)));


61 


62 


63  samples = new IntRange(0, 60);


64  fixedSamples = new IntRange(20, 40);


65 


66  //test simple case


67  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 0);


68  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 10)));


69  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 1);


70  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(50, 10)));


71  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 2);


72  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(0, 10)));


73  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 3);


74  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(10, 10)));


75 


76  //test with overlap


77  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 30, overlap: 25, iteration: 0);


78  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 20).Concat(Enumerable.Range(0, 10))));


79  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 30, overlap: 25, iteration: 1);


80  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(45, 15).Concat(Enumerable.Range(0, 15))));


81  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 30, overlap: 25, iteration: 2);


82  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(50, 10).Concat(Enumerable.Range(0, 20))));


83  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 30, overlap: 25, iteration: 3);


84  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(55, 5).Concat(Enumerable.Range(0, 20).Concat(Enumerable.Range(40, 5)))));


85  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 30, overlap: 25, iteration: 4);


86  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(0, 20).Concat(Enumerable.Range(40, 10))));


87  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 30, overlap: 25, iteration: 5);


88  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(5, 15).Concat(Enumerable.Range(40, 15))));


89 


90  samples = new IntRange(10, 60);


91  fixedSamples = new IntRange(20, 40);


92  //test simple case


93  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 0);


94  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 10)));


95  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 1);


96  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(50, 10)));


97  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 2);


98  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(10, 10)));


99  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 10, overlap: 0, iteration: 3);


100  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 10)));


101 


102  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 20, overlap: 15, iteration: 0);


103  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(40, 20)));


104  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 20, overlap: 15, iteration: 1);


105  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(45, 15).Concat(Enumerable.Range(10, 5))));


106  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 20, overlap: 15, iteration: 2);


107  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(50, 10).Concat(Enumerable.Range(10, 10))));


108  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 20, overlap: 15, iteration: 3);


109  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(55, 5).Concat(Enumerable.Range(10, 10).Concat(Enumerable.Range(40, 5)))));


110  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 20, overlap: 15, iteration: 4);


111  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(10, 10).Concat(Enumerable.Range(40, 10))));


112  rows = ConsecutiveSamplesEvaluator.GenerateRows(samples, fixedSamples, consecutiveSamples: 20, overlap: 15, iteration: 5);


113  Assert.IsTrue(rows.SequenceEqual(Enumerable.Range(15, 5).Concat(Enumerable.Range(40, 15))));


114 


115 


116  //error cases


117  //consecutive samples larger than remaining samples


118  //fixed samples partition invalid


119  }


120  }


121  }

