public void TestIndexOfElement() { // Arrange. IEnumerable<int> list = new List<int> { 1, 2, 3 }; // Assert. Assert.AreEqual(0, list.IndexOf(1)); Assert.AreEqual(2, list.IndexOf(3)); Assert.AreEqual(-1, list.IndexOf(5)); }
public void Sorting_Strings_WorksCorrectly() { var first = new ComparableSemanticType<string>("A"); var second = new ComparableSemanticType<string>("B"); var third = new ComparableSemanticType<string>("C"); var list = new List<ComparableSemanticType<string>>() { second, third, first }; list.Sort(); Assert.That(list.IndexOf(first) == 0); Assert.That(list.IndexOf(second) == 1); Assert.That(list.IndexOf(third) == 2); }
public void Sorting_Ints_WorksCorrectly() { var first = new ComparableSemanticType<int>(0); var second = new ComparableSemanticType<int>(1); var third = new ComparableSemanticType<int>(2); var list = new List<ComparableSemanticType<int>>() { second, third, first }; list.Sort(); Assert.That(list.IndexOf(first) == 0); Assert.That(list.IndexOf(second) == 1); Assert.That(list.IndexOf(third) == 2); }
public void Init() { var taskList = new List<AttemptChainTaskHandler<int>>(); for (var i = 0; i < _taskCount; i++) { var newTask = new AttemptChainTaskHandler<int>(new DemoAttemptChainTask() { Index = i }); taskList.Add(newTask); } foreach (var task in taskList.Where(task => taskList.IndexOf(task) != taskList.IndexOf(taskList.Last()))) { task.RegisterNext(taskList[taskList.IndexOf(task) + 1]); } _tasks = taskList; }
public void TestIndexOfPredicate() { // Arrange. IEnumerable<int> list = new List<int> { 1, 2, 3 }; // Assert. Assert.AreEqual(2, list.IndexOf(i => i > 2)); }
public void TestIndexOf () { List<int> l = new List<int>(); l.Add (100); l.Add (200); Assert ("Could not find value", l.IndexOf (200) == 1); }
public void list_test() { List<int> list = new List<int>(); list.Add(100); list.Add(101); list.Add(102); int i = list.IndexOf(101); Assert.AreEqual(1, i); }
public void TestSortPluginNames() { List<string> orderBy = new List<string> { "A", "B", "C" }; List<string> pluginNames = new List<string> { "C", "X", "B", "A" }; Func<string, int> keyFunc = x => orderBy.IndexOf(x); PluginLoader.SortPluginNames(pluginNames, keyFunc); Assert.AreEqual("A", pluginNames[0]); Assert.AreEqual("B", pluginNames[1]); Assert.AreEqual("C", pluginNames[2]); Assert.AreEqual("X", pluginNames[3]); }
public void TestSortPluginNamesWithStripPluginModule() { List<string> orderBy = new List<string> { "A", "B", "C" }; List<string> pluginNames = new List<string> { "plugin/C", "plugin/X", "sample_plugin/B", "plugin/A" }; Func<string, int> keyFunc = x => orderBy.IndexOf(PluginLoader.StripPluginModule(x)); PluginLoader.SortPluginNames(pluginNames, keyFunc); Assert.AreEqual("plugin/A", pluginNames[0]); Assert.AreEqual("sample_plugin/B", pluginNames[1]); Assert.AreEqual("plugin/C", pluginNames[2]); Assert.AreEqual("plugin/X", pluginNames[3]); }
public void TestOutOfRange () { List<int> l = new List<int> (4); bool errorThrown = false; try { l.IndexOf (0, 0, 4); } catch (ArgumentOutOfRangeException){ errorThrown = true; } Assert ("Out of range count exception not thrown", errorThrown); }
public void AllNodesAreCoveredDuringIteration() { var nodeArray = new List<Node>(); for (var i = 0; i < 5; ++i) { var node = new MockNode(); nodeArray.Add(node); _nodes.Add(node); } for (var node = _nodes.Head; node != null; node = node.Next) { var index = nodeArray.IndexOf(node); nodeArray.RemoveAt(index); } Assert.AreEqual(0, nodeArray.Count); }
public void TestListOperation() { List<IPEndPoint> endpointList = new List<IPEndPoint>(); IPEndPoint endpoint1 = CreateEndPoint("192.10.10.98", 1); IPEndPoint endpoint2 = CreateEndPoint("192.10.10.99", 2); IPEndPoint endpoint3 = CreateEndPoint("192.10.10.100", 3); endpointList.Add(endpoint1); endpointList.Add(endpoint2); endpointList.Add(endpoint3); IPEndPoint wanted = CreateEndPoint("192.10.10.99", 2); int position = endpointList.IndexOf(wanted); Assert.AreEqual(1, position); Assert.AreNotSame(wanted, endpointList[position]); Assert.IsTrue(endpointList[position].Equals(wanted)); endpointList.Remove(wanted); CollectionAssert.AreEqual(new[] { endpoint1, endpoint3 }, endpointList); }
public void NodeListContainsAllMatchingEntities() { var entities = new List<EntityBase>(); for (var i = 0; i < 5; ++i) { var entity = new EntityBase(); entity.Add(new Vector2()); entities.Add(entity); _family.NewEntity(entity); _family.NewEntity(new EntityBase()); } var nodes = _family.NodeList; for (var node = nodes.Head; node != null; node = node.Next) { entities.RemoveAt(entities.IndexOf(node.Entity)); } Assert.AreEqual(0, entities.Count); }
public void CombinesDataBlocks( [Values(100, 500, 1000, 5000)] double blockMilliseconds, [Values(5000, 10000)] double sampleRateHz, [Values(1, 4)] int numStim ) { var parameters = new Dictionary<string, object>(); var sampleRate = new Measurement((decimal)sampleRateHz, "Hz"); var data = new List<IOutputData>(); var stimuli = new List<IStimulus>(); for (int i = 0; i < numStim; i++) { IOutputData d = new OutputData(Enumerable.Range(0, (int)TimeSpan.FromSeconds(3).Samples(new Measurement((decimal)sampleRateHz, "Hz"))) .Select(j => new Measurement(j, "units")).ToList(), sampleRate, false); data.Add(d); stimuli.Add(new RenderedStimulus((string)"RenderedStimulus" + i, (IDictionary<string, object>)parameters, d)); } var combined = new CombinedStimulus("CombinedStimulus", new Dictionary<string, object>(), stimuli, CombinedStimulus.Add); var blockSpan = TimeSpan.FromMilliseconds(blockMilliseconds); IEnumerator<IOutputData> iter = combined.DataBlocks(blockSpan).GetEnumerator(); while (iter.MoveNext()) { IOutputData expectedData = null; foreach (var d in data.ToList()) { var cons = d.SplitData(blockSpan); data[data.IndexOf(d)] = cons.Rest; expectedData = expectedData == null ? cons.Head : expectedData.Zip(cons.Head, (m1, m2) => new Measurement(m1.QuantityInBaseUnits + m2.QuantityInBaseUnits, 0, m1.BaseUnits)); } Assert.That(iter.Current.Duration, Is.EqualTo(expectedData.Duration)); Assert.That(iter.Current.Data, Is.EqualTo(expectedData.Data)); } }
public void FamilyContainsAllMatchingEntities() { var entities = new List<Entity>(); for (var i = 0; i < 5; ++i) { var entity = new Entity(); entity.Add(new Vector2()); entity.Add(new Matrix4x4()); entities.Add(entity); _game.AddEntity(entity); } var nodes = _game.GetNodeList<MockNode>(); for (var node = nodes.Head; node != null; node = node.Next) { var index = entities.IndexOf(node.Entity); entities.RemoveAt(index); } Assert.AreEqual(0, entities.Count); }
public void RemovingCurrentNodeDuringIterationIsValid() { var nodeArray = new List<Node>(); for (var i = 0; i < 5; ++i) { var node = new MockNode(); nodeArray.Add(node); _nodes.Add(node); } var count = 0; for (var node = _nodes.Head; node != null; node = node.Next) { var index = nodeArray.IndexOf(node); nodeArray.RemoveAt(index); if (++count == 2) { _nodes.Remove(node); } } Assert.AreEqual(0, nodeArray.Count); }
public void SetUp() { words = Values.AtoZ().SelectMany(c => Enumerable.Range(1, 100).Select(i => c + i)).ToList(); partitions = Values.AtoZ().Select(c => Partition.Where<string>(s => s.StartsWith(c), named: c)); partitionedStream = Stream .Partitioned<string, int, string>( query: async (q, partition) => { var wordsInPartition = words .Skip(q.Cursor.Position) .Where(partition.Contains); var b = wordsInPartition .Take(q.BatchSize.Value); return b; }, advanceCursor: (query, batch) => { query.Cursor.AdvanceTo(words.IndexOf(batch.Last()) + 1); }); Formatter.ListExpansionLimit = 100; Formatter<Projection<HashSet<int>, int>>.RegisterForAllMembers(); }
public void ArbitraryStuff() { var boundingBox = new Box(0, 0, 500, 500); var picture = new Box(60, 60, 100, 100); var picture2 = new Box(300, 80, 400, 200); var picture3 = new Box(10, 130, 100, 200); var pictures = new List<Box> {picture, picture2, picture3}; var horizontalLines = new List<HorizontalLine>{ new HorizontalLine(boundingBox.Y1), new HorizontalLine(boundingBox.Y2)}; var verticalLines = new List<VerticalLine>{new VerticalLine(boundingBox.X1), new VerticalLine(boundingBox.X2)}; pictures.ForEach(box => { horizontalLines.Add(new HorizontalLine(box.Y1)); horizontalLines.Add(new HorizontalLine(box.Y2)); verticalLines.Add(new VerticalLine(box.X1)); verticalLines.Add(new VerticalLine(box.X2)); }); horizontalLines.Sort((line1,line2) => { if (line1.Y == line2.Y) return 0; if (line1.Y < line2.Y) return -1; return 1; }); verticalLines.Sort((line1,line2) => { if (line1.X == line2.X) return 0; if (line1.X < line2.X) return -1; return 1; }); var allMergedBoxes = new List<Box>(); foreach (var horizontalLine in horizontalLines) { if (horizontalLines.Last() == horizontalLine) break; var top = horizontalLine; var bottom = horizontalLines[horizontalLines.IndexOf(horizontalLine) + 1]; currentBox = null; foreach (var verticalLine in verticalLines) { if (verticalLines.Last() == verticalLine) { TerminateBox(currentBox, allMergedBoxes); break; } var left = verticalLine; var right = verticalLines[verticalLines.IndexOf(verticalLine) + 1]; if (new Box(left.X, top.Y, right.X, bottom.Y).OverlapsWith(pictures)) { TerminateBox(currentBox, allMergedBoxes); continue; } AddToCurrentBox(currentBox, left.X, top.Y, right.X, bottom.Y); } } allMergedBoxes.ForEach(box => Console.Out.WriteLine(box)); }
private bool CompareShape( List<IntPoint> shape1, List<IntPoint> shape2 ) { if ( shape1.Count != shape2.Count ) return false; if ( shape1.Count == 0 ) return true; int index = shape1.IndexOf( shape2[0] ); if ( index == -1 ) return false; index++; for ( int i = 1; i < shape2.Count; i++, index++ ) { if ( index >= shape1.Count ) index = 0; if ( !shape1[index].Equals( shape2[i] ) ) return false; } return true; }
public void TestRandomTupleListSorting(int length) { var random = new System.Random(0); var keys = new List<int>(length); var items = new List<int>(length); var keysCopy = new int[length]; for (var i = 0; i < length; i++) { var value = random.Next(); keys.Add(value); keysCopy[i] = value; items.Add(-value); } Sorting.Sort(keys, items); for (var i = 1; i < length; i++) { Assert.IsTrue(keys[i] >= keys[i - 1], "Sort Order - " + i); Assert.AreEqual(items[i], -keys[i], "Items Permutation - " + i); } for (var i = 0; i < keysCopy.Length; i++) { Assert.IsTrue(keys.IndexOf(keysCopy[i]) >= 0, "All keys still there - " + i); } }
public void IndexOfCorrectlyThrowsNullException() { var list = new List<double>(); list.IndexOf(null); }
public void GetObjIndexTest() { var lp = Cache.LanguageProject; const int flid = LangProjectTags.kflidStyles; // Add a text. var style = Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create(); lp.StylesOC.Add(style); var hvos = new List<int>(lp.StylesOC.ToHvoArray()); var idx1 = hvos.IndexOf(style.Hvo); var idx2 = m_sda.GetObjIndex(lp.Hvo, flid, style.Hvo); Assert.AreEqual(idx1, idx2, "Wrong index for new Text."); lp.StylesOC.Remove(style); Assert.AreEqual(-1, m_sda.GetObjIndex(lp.Hvo, flid, lp.Hvo), "Wrong index for LP."); }
public void TestGetBATBlockAndIndex() { HeaderBlock header = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS); List<BATBlock> blocks = new List<BATBlock>(); int offset; // First, try a one BAT block file header.BATCount = (1); blocks.Add( BATBlock.CreateBATBlock(header.BigBlockSize, new ByteBuffer(512, 512)) ); offset = 0; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1; Assert.AreEqual(1, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 127; Assert.AreEqual(127, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); // Now go for one with multiple BAT blocks header.BATCount = (2); blocks.Add( BATBlock.CreateBATBlock(header.BigBlockSize, new ByteBuffer(512, 512)) ); offset = 0; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 127; Assert.AreEqual(127, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 128; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(1, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 129; Assert.AreEqual(1, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(1, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); // The XBAT count makes no difference, as we flatten in memory header.BATCount = (1); header.XBATCount = (1); offset = 0; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 126; Assert.AreEqual(126, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 127; Assert.AreEqual(127, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 128; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(1, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 129; Assert.AreEqual(1, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(1, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); // Check with the bigger block size too header = new HeaderBlock(POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS); offset = 0; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1022; Assert.AreEqual(1022, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1023; Assert.AreEqual(1023, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1024; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(1, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); // Biggr block size, back to real BATs header.BATCount = (2); offset = 0; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1022; Assert.AreEqual(1022, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1023; Assert.AreEqual(1023, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(0, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); offset = 1024; Assert.AreEqual(0, BATBlock.GetBATBlockAndIndex(offset, header, blocks).Index); Assert.AreEqual(1, blocks.IndexOf(BATBlock.GetBATBlockAndIndex(offset, header, blocks).Block)); }
public void TestIndexOf() { using (var map = new MemoryMapStream()) { var list = new List<int>(map); for (var i = 0; i < 1024; i++) { list.Add(i); } for(var i = 0; i < 1024; i++) { Assert.AreEqual(i, list.IndexOf(i)); } Assert.AreEqual(-1, list.IndexOf(2048)); } }
public void Object_Property_Foreach_Generic_ValueAndNameAndSetter() { var person = new OtherPerson2(25) { FirstName = "FirstName", LastName = "LastName", MiddleName = "MiddleName", NickName = "NickName", Suffix = "Suffix", Title = "Title", NumberOfKids = 3 }; //25 added for the age property var allPropertyNames = new List<string> { "FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids", "Age" }; var strProperties = new HashSet<string>(new[] {"FirstName", "LastName", "MiddleName", "NickName", "Suffix", "Title", "NumberOfKids"}); var intProperties = new HashSet<string>(new[] { "NumberOfKids", "Age" }); var allPropertiesTouched = Enumerable.Repeat(false, 8).ToList(); int increment = 0; _.Object.Property.Each<string>(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = "Some value " + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); }); _.Object.Property.Each<int>(person, (value, name, setter) => { var indexOf = allPropertyNames.IndexOf(name); if (indexOf == -1) { Assert.Fail("Could not find property " + name); } else { allPropertiesTouched[indexOf] = true; } var actualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(actualValue.Equals(value)); if (name == "Age") { Assert.IsNull(setter, "Setter should be null for the 'Age' property because it does not have a setter"); } else { // doing this in case an error happens where multiple values are assigned or // all of them are assigned a value (using the same value for everything would give false positive result then) var newValue = 100 + increment; setter(newValue); increment++; //now get the new value see if it matches var newActualValue = typeof(OtherPerson2).GetProperty(name).GetValue(person); Assert.IsTrue(newActualValue.Equals(newValue)); } }); //then check all expected properties were called var propertiesMissed = new List<string>(); for (int i = 0; i < allPropertiesTouched.Count; i++) { if (!allPropertiesTouched[i]) { propertiesMissed.Add(allPropertyNames[i]); } } if (propertiesMissed.Any()) { Assert.Fail("Missed the following properties " + string.Join(", ", propertiesMissed)); } }
public void ReadJuneGDEMSalinityFile() { StringAssert.EndsWith("sgdemv3s06.nc", TestFileThatExists, "The passed-in file does not appear to be the June GDEMv3 Salinity file"); var ncFile = NetCDFFile.Open(TestFileThatExists); Assert.NotNull(ncFile); Assert.AreEqual(9, ncFile.Attributes.Count); var ncAttChar = (NcAttChar)ncFile.Attributes[0]; StringAssert.AreEqualIgnoringCase("CONVENTION", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("NAVO_netcdf_v1.0", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[1]; StringAssert.AreEqualIgnoringCase("INSTITUTION", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("Naval Oceanographic Office", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[2]; StringAssert.AreEqualIgnoringCase("CONTACT", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("NAVO, Code N312", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[3]; StringAssert.AreEqualIgnoringCase("HISTORY", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("created: 01-Oct-2002 14:46:18", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[4]; StringAssert.AreEqualIgnoringCase("DESCRIPTION", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("GDEMV 3.0", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[5]; StringAssert.AreEqualIgnoringCase("CLASSIFICATION_LEVEL", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("UNCLASSIFIED", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[6]; StringAssert.AreEqualIgnoringCase("DISTRIBUTION_STATEMENT", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("DISTRIBUTION STATEMENT A: APPROVED FOR PUBLIC RELEASE: DISTRIBUTION IS UNLIMITED", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[7]; StringAssert.AreEqualIgnoringCase("DOWNGRADE_DATE", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("N/A", ncAttChar.Value); ncAttChar = (NcAttChar)ncFile.Attributes[8]; StringAssert.AreEqualIgnoringCase("CLASSIFICATION_AUTHORITY", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("N/A", ncAttChar.Value); var ncVarDouble = (NcVarDouble)ncFile.Variables[0]; StringAssert.AreEqualIgnoringCase("lat", ncVarDouble.Name); Assert.AreEqual(1, ncVarDouble.Dimensions.Count); Assert.AreEqual(689, ncVarDouble.Dimensions[0].Length); ncAttChar = (NcAttChar)ncVarDouble.Attributes[0]; StringAssert.AreEqualIgnoringCase("long_name", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("Latitude", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[1]; StringAssert.AreEqualIgnoringCase("units", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("degrees_north", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[2]; StringAssert.AreEqualIgnoringCase("FORTRAN_format", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("e13.6", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[3]; StringAssert.AreEqualIgnoringCase("point_spacing", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("even", ncAttChar.Value); var ncAttInt = (NcAttInt)ncVarDouble.Attributes[4]; StringAssert.AreEqualIgnoringCase("Navo_code", ncAttInt.Name); Assert.AreEqual(1, ncAttInt.Value.Length); Assert.AreEqual(1, ncAttInt.Value[0]); var latitudes = new List<double>(); for (var index = 0; index < 689; index++) latitudes.Add(ncVarDouble[(uint)index]); var lat26N = latitudes.IndexOf(26); Debug.WriteLine("Latitude 26N is at index {0}", lat26N); ncVarDouble = (NcVarDouble)ncFile.Variables[1]; StringAssert.AreEqualIgnoringCase("lon", ncVarDouble.Name); Assert.AreEqual(1, ncVarDouble.Dimensions.Count); Assert.AreEqual(1440, ncVarDouble.Dimensions[0].Length); ncAttChar = (NcAttChar)ncVarDouble.Attributes[0]; StringAssert.AreEqualIgnoringCase("long_name", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("Longitude", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[1]; StringAssert.AreEqualIgnoringCase("units", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("degrees_east", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[2]; StringAssert.AreEqualIgnoringCase("FORTRAN_format", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("e13.6", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[3]; StringAssert.AreEqualIgnoringCase("point_spacing", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("even", ncAttChar.Value); ncAttInt = (NcAttInt)ncVarDouble.Attributes[4]; StringAssert.AreEqualIgnoringCase("Navo_code", ncAttInt.Name); Assert.AreEqual(1, ncAttInt.Value.Length); Assert.AreEqual(2, ncAttInt.Value[0]); var longitudes = new List<double>(); for (var index = 0; index < 1440; index++) longitudes.Add(ncVarDouble[(uint)index]); var lon53E = longitudes.IndexOf(53); Debug.WriteLine("Longitude 53E is at index {0}", lon53E); ncVarDouble = (NcVarDouble)ncFile.Variables[2]; StringAssert.AreEqualIgnoringCase("depth", ncVarDouble.Name); Assert.AreEqual(1, ncVarDouble.Dimensions.Count); Assert.AreEqual(78, ncVarDouble.Dimensions[0].Length); ncAttChar = (NcAttChar)ncVarDouble.Attributes[0]; StringAssert.AreEqualIgnoringCase("long_name", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("Depth", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[1]; StringAssert.AreEqualIgnoringCase("units", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("meters", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[2]; StringAssert.AreEqualIgnoringCase("FORTRAN_format", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("e13.6", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[3]; StringAssert.AreEqualIgnoringCase("point_spacing", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("uneven", ncAttChar.Value); ncAttInt = (NcAttInt)ncVarDouble.Attributes[4]; StringAssert.AreEqualIgnoringCase("Navo_code", ncAttInt.Name); Assert.AreEqual(1, ncAttInt.Value.Length); Assert.AreEqual(5, ncAttInt.Value[0]); ncVarDouble = (NcVarDouble)ncFile.Variables[3]; StringAssert.AreEqualIgnoringCase("time", ncVarDouble.Name); Assert.AreEqual(1, ncVarDouble.Dimensions.Count); Assert.AreEqual(1, ncVarDouble.Dimensions[0].Length); ncAttChar = (NcAttChar)ncVarDouble.Attributes[0]; StringAssert.AreEqualIgnoringCase("FORTRAN_format", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("F10.2", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[1]; StringAssert.AreEqualIgnoringCase("units", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("hour since 0000-01-01 00:00:00", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[2]; StringAssert.AreEqualIgnoringCase("type", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("EVEN", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarDouble.Attributes[3]; StringAssert.AreEqualIgnoringCase("time_origin", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("1-Jan-0000 00:00:00", ncAttChar.Value); ncAttInt = (NcAttInt)ncVarDouble.Attributes[4]; StringAssert.AreEqualIgnoringCase("Navo_code", ncAttInt.Name); Assert.AreEqual(1, ncAttInt.Value.Length); Assert.AreEqual(13, ncAttInt.Value[0]); var ncVarShort = (NcVarShort)ncFile.Variables[4]; StringAssert.AreEqualIgnoringCase("salinity", ncVarShort.Name); Assert.AreEqual(3, ncVarShort.Dimensions.Count); Assert.AreEqual(78, ncVarShort.Dimensions[0].Length); Assert.AreEqual(689, ncVarShort.Dimensions[1].Length); Assert.AreEqual(1440, ncVarShort.Dimensions[2].Length); var ncAttShort = (NcAttShort)ncVarShort.Attributes[0]; StringAssert.AreEqualIgnoringCase("_FillValue", ncAttShort.Name); Assert.AreEqual(1, ncAttShort.Value.Length); Assert.AreEqual(-32000, ncAttShort.Value[0]); ncAttShort = (NcAttShort)ncVarShort.Attributes[1]; StringAssert.AreEqualIgnoringCase("missing_value", ncAttShort.Name); Assert.AreEqual(1, ncAttShort.Value.Length); Assert.AreEqual(-32000, ncAttShort.Value[0]); ncAttChar = (NcAttChar)ncVarShort.Attributes[2]; StringAssert.AreEqualIgnoringCase("long_name", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("Salinity", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarShort.Attributes[3]; StringAssert.AreEqualIgnoringCase("units", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("psu", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarShort.Attributes[4]; StringAssert.AreEqualIgnoringCase("FORTRAN_format", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("e13.6", ncAttChar.Value); ncAttChar = (NcAttChar)ncVarShort.Attributes[5]; StringAssert.AreEqualIgnoringCase("coordinate_system", ncAttChar.Name); StringAssert.AreEqualIgnoringCase("orthogonal_constant-spacing", ncAttChar.Value); var ncAttFloat = (NcAttFloat)ncVarShort.Attributes[6]; StringAssert.AreEqualIgnoringCase("scale_factor", ncAttFloat.Name); Assert.AreEqual(1, ncAttFloat.Value.Length); Assert.AreEqual(0.001f, ncAttFloat.Value[0]); var scaleFactor = ncAttFloat.Value[0]; ncAttFloat = (NcAttFloat)ncVarShort.Attributes[7]; StringAssert.AreEqualIgnoringCase("add_offset", ncAttFloat.Name); Assert.AreEqual(1, ncAttFloat.Value.Length); Assert.AreEqual(15, ncAttFloat.Value[0]); var addOffset = ncAttFloat.Value[0]; ncAttInt = (NcAttInt)ncVarShort.Attributes[8]; StringAssert.AreEqualIgnoringCase("Navo_code", ncAttInt.Name); Assert.AreEqual(1, ncAttInt.Value.Length); Assert.AreEqual(16, ncAttInt.Value[0]); // The following test locations, depths and expected results are extracted from the official GDEM documentation file Assert.That(38.660, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 0, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(38.678, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 1, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(38.697, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 2, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(38.737, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 3, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(38.794, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 4, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(38.867, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 5, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.177, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 6, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.482, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 7, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.652, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 8, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.776, Is.EqualTo(addOffset + scaleFactor * ncVarShort[ 9, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.830, Is.EqualTo(addOffset + scaleFactor * ncVarShort[10, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.879, Is.EqualTo(addOffset + scaleFactor * ncVarShort[11, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.921, Is.EqualTo(addOffset + scaleFactor * ncVarShort[12, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.983, Is.EqualTo(addOffset + scaleFactor * ncVarShort[13, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(39.985, Is.EqualTo(addOffset + scaleFactor * ncVarShort[14, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(40.001, Is.EqualTo(addOffset + scaleFactor * ncVarShort[15, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(40.004, Is.EqualTo(addOffset + scaleFactor * ncVarShort[16, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(40.000, Is.EqualTo(addOffset + scaleFactor * ncVarShort[17, (uint)lat26N, (uint)lon53E]).Within(0.00001)); Assert.That(40.011, Is.EqualTo(addOffset + scaleFactor * ncVarShort[18, (uint)lat26N, (uint)lon53E]).Within(0.00001)); }
public void InterfaceImplementation() { // prepare our test lists var referenceList = new List<NbtTag> { new NbtInt(1), new NbtInt(2), new NbtInt(3) }; var testTag = new NbtInt(4); var originalList = new NbtList(referenceList); // check IList implementation IList iList = originalList; CollectionAssert.AreEqual(referenceList, iList); // check IList<NbtTag> implementation IList<NbtTag> iGenericList = originalList; CollectionAssert.AreEqual(referenceList, iGenericList); Assert.IsFalse(iGenericList.IsReadOnly); // check IList.Add referenceList.Add(testTag); iList.Add(testTag); CollectionAssert.AreEqual(referenceList, iList); // check IList.IndexOf Assert.AreEqual(referenceList.IndexOf(testTag), iList.IndexOf(testTag)); Assert.IsTrue(iList.IndexOf(null) < 0); // check IList<NbtTag>.IndexOf Assert.AreEqual(referenceList.IndexOf(testTag), iGenericList.IndexOf(testTag)); Assert.IsTrue(iGenericList.IndexOf(null) < 0); // check IList.Contains Assert.IsTrue(iList.Contains(testTag)); // check IList.Remove iList.Remove(testTag); Assert.IsFalse(iList.Contains(testTag)); // check IList.Insert iList.Insert(0, testTag); Assert.AreEqual(0, iList.IndexOf(testTag)); // check IList.RemoveAt iList.RemoveAt(0); Assert.IsFalse(iList.Contains(testTag)); // check misc IList properties Assert.IsFalse(iList.IsFixedSize); Assert.IsFalse(iList.IsReadOnly); Assert.IsFalse(iList.IsSynchronized); Assert.NotNull(iList.SyncRoot); // check IList.CopyTo var exportTest = new NbtInt[iList.Count]; iList.CopyTo(exportTest, 0); CollectionAssert.AreEqual(iList, exportTest); // check IList.this[int] for (int i = 0; i < iList.Count; i++) { Assert.AreEqual(originalList[i], iList[i]); iList[i] = new NbtInt(i); } // check IList.Clear iList.Clear(); Assert.AreEqual(0, iList.Count); Assert.Less(iList.IndexOf(testTag), 0); }
private void VerifyErrors(List<string> errorMessages, int errorsCount) { List<string> actualErrors = GetErrorMessages(); int actualErrorsCount = actualErrors.Count; Assert.AreEqual(errorsCount, actualErrorsCount); foreach (string expectError in errorMessages) { string actualError = actualErrors[errorMessages.IndexOf(expectError)]; Assert.AreEqual(expectError, actualError); } }
public void TestRandomTupleListSorting() { const int len = 0x1 << 10; SystemRandomSource random = new SystemRandomSource(); List<int> keys = new List<int>(len); List<int> items = new List<int>(len); int[] keysCopy = new int[len]; for(int i = 0; i < len; i++) { int value = random.Next(); keys.Add(value); keysCopy[i] = value; items.Add(-value); } Sorting.Sort(keys, items); for(int i = 1; i < len; i++) { Assert.That(keys[i] >= keys[i - 1], "Sort Order - " + i.ToString()); Assert.That(items[i], Is.EqualTo(-keys[i]), "Items Permutation - " + i.ToString()); } for(int i = 0; i < keysCopy.Length; i++) { Assert.That(keys.IndexOf(keysCopy[i]) >= 0, "All keys still there - " + i.ToString()); } }
private void VerifyControllerList(List<string> expectedList, string region) { Page.LoginPage.TopMainMenu.NavigateToControlerSetupPage(); Page.ControllerSetupPage.AddControllerButton.Click(); ReadOnlyCollection<string> actualList = Page.ControllerGeneralSetupTabPage.GetControllerModelList(); //new List<string>() { "A", "B", "C" }.AsReadOnly(); foreach(string controller in actualList) { if(actualList.IndexOf(controller) != expectedList.IndexOf(controller)) { Assert.Fail("Order of controller {0} for region {1} is different Expected order:{2}, Actual order:{3}", controller, region,expectedList.IndexOf(controller)+1, actualList.IndexOf(controller)+1); } } }