From a15b9b9be388f878e6d9927ade45663d550e03ab Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Wed, 17 Aug 2016 11:38:27 +0200
Subject: [PATCH] Tests: Added GetSection Tests for Fast GetSection with Arrays

---
 .../Models/Simulation/GetSectionTest.cs       | 64 +++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 VectoCore/VectoCoreTest/Models/Simulation/GetSectionTest.cs

diff --git a/VectoCore/VectoCoreTest/Models/Simulation/GetSectionTest.cs b/VectoCore/VectoCoreTest/Models/Simulation/GetSectionTest.cs
new file mode 100644
index 0000000000..9c5fd916da
--- /dev/null
+++ b/VectoCore/VectoCoreTest/Models/Simulation/GetSectionTest.cs
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using NUnit.Framework;
+using TUGraz.VectoCommon.Utils;
+
+namespace TUGraz.VectoCore.Tests.Models.Simulation
+{
+	[TestFixture]
+	public class GetSectionTests
+	{
+		public class Entry
+		{
+			public readonly PerSecond EngineSpeed;
+			public NewtonMeter Torque;
+
+			public Entry(PerSecond engineSpeed, NewtonMeter torque)
+			{
+				EngineSpeed = engineSpeed;
+				Torque = torque;
+			}
+		}
+
+		[Test]
+		public void TestGetSection()
+		{
+			var entries = new List<Entry>();
+			for (var i = 0; i < 10; i++) {
+				entries.Add(new Entry(i.RPMtoRad(), i.SI<NewtonMeter>()));
+			}
+			var entryArr = entries.ToArray();
+
+			foreach (var val in new[] { -1, 0, 1, 5, 8, 9, 10 }) {
+				var sw = Stopwatch.StartNew();
+				var s = entries.GetSection(e => val > e.EngineSpeed);
+				sw.Stop();
+				//Console.WriteLine("Iterator: " + sw.Elapsed);
+
+				sw.Restart();
+				var s1 = entryArr.GetSection(e => val > e.EngineSpeed);
+				sw.Stop();
+				//Console.WriteLine("Array:    " + sw.Elapsed);
+
+				Assert.AreSame(s.Item1, s1.Item1);
+				Assert.AreSame(s.Item2, s1.Item2);
+			}
+
+			foreach (var val in new[] { -1, 0, 1, 5, 8, 9, 10 }) {
+				var sw = Stopwatch.StartNew();
+				var s = entries.GetSection(e => val < e.EngineSpeed);
+				sw.Stop();
+				Console.WriteLine("Iterator: " + sw.Elapsed);
+
+				sw.Restart();
+				var s1 = entryArr.GetSection(e => val < e.EngineSpeed);
+				sw.Stop();
+				Console.WriteLine("Array:    " + sw.Elapsed);
+
+				Assert.AreSame(s.Item1, s1.Item1);
+				Assert.AreSame(s.Item2, s1.Item2);
+			}
+		}
+	}
+}
\ No newline at end of file
-- 
GitLab