public void From2DCollectionTest() { var target = new List <ICollection <int> > { new List <int> { 1, 2 }, new List <int> { 3, 4 }, new List <int> { 5, 6 } }; var actual = ArrayProvider.To2DArray(target); Assert.Equal(2, actual.Rank); Assert.Equal(3, actual.GetLength(0)); Assert.Equal(2, actual.GetLength(1)); int r0 = 0, r1 = 0; foreach (var c0 in target) { foreach (var value in c0) { var actualValue = actual[r0, r1]; Assert.Equal(value, actualValue); //, string.Format("Value at [{0}, {1}] was not expected, expected {2} but found {3}", r0, r1, value, actualValue)); r1++; } r0++; r1 = 0; } }
public void Travel(IReadVisitor visitor, MultidimensionalArrayGraph graph) { ValueState state; state = visitor.TryVisit(_argsValue); if (state != ValueState.NotFound) { if (state == ValueState.Found) { ICollection <ICollection <int> > c = new List <ICollection <int> >(); while (visitor.TryVisit(VisitArgs.CollectionInCollection) == ValueState.Found) { ICollection <int> cv = new List <int>(); int?cvv; while (visitor.TryVisitValue(VisitArgs.CollectionItem, out cvv) && cvv.HasValue) { cv.Add(cvv.Value); } visitor.Leave(VisitArgs.CollectionInCollection); c.Add(cv); } graph.Value = ArrayProvider.To2DArray(c); visitor.Leave(_argsValue); } else { graph.Value = null; } } }
public void FromEmpty2DCollectionTest() { var target = new List <ICollection <int> >(); var actual = ArrayProvider.To2DArray(target); Assert.Equal(2, actual.Rank); Assert.Equal(0, actual.GetLength(0)); Assert.Equal(0, actual.GetLength(1)); }