using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Seshat.UnitTests { public class SampleSchemaTests : UnitTestSharp.TestFixture { public void ToLuaTable_Basic() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; instance1.dict = new Dictionary() { {"1", 'c'}, {"5", 'f'}, {"2", 'p'} }; var lua = table.SerializeToLuaTable(); var expected = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { [ ""1"" ] = ""c"", [ ""5"" ] = ""f"", [ ""2"" ] = ""p"", }, }, }"; CheckEqual(expected, lua); } public void ToLuaTable_EnumerableWithOneElement() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1 }; instance1.dict = new Dictionary() { {"1", 'c'}, {"5", 'f'}, {"2", 'p'} }; var lua = table.SerializeToLuaTable(); var expected =@"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = ""1"", dict = { [ ""1"" ] = ""c"", [ ""5"" ] = ""f"", [ ""2"" ] = ""p"", }, }, }"; CheckEqual(expected, lua); } public void ToLuaTable_MapWithOneElement() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; instance1.dict = new Dictionary() { {"0", 'c'}, }; var lua = table.SerializeToLuaTable(); var expected = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = ""c"", }, }"; CheckEqual(expected, lua); } public void ToLuaTable_KeyContainsBrackets() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; instance1.dict = new Dictionary() { {"\"", '"'}, {"\"=[", 'a'}, }; var lua = table.SerializeToLuaTable(); var expected = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { [ [[""]] ] = [[""]], [ [[""=[]] ] = ""a"", }, }, }"; CheckEqual(expected, lua); } public void FromLuaTable_Basic() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = {""4"", ""7"", ""12""}, doubles = {""1"", ""2""}, collection = {""1"", ""2"", ""3"", ""4"", ""5""}, bakedList = {""1"", ""2"", ""3""}, dict = { [ ""1"" ] = ""c"", [ [[5]] ] = ""f"", [ [=[-2]=] ] = ""p""}, }, }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(1, table.RowCount); var instance = table.GetRow(0); CheckEqual(new Tuple(10, "hello"), instance.AandB); CheckEqual(11, instance.composite_element1); CheckEqual("goodbye", instance.composite_element2); CheckEqual(new DateTime(1999, 12, 31, 13, 0, 0), instance.date); CheckEqual(new int[3] { 4, 7, 12 }, instance.triples); CheckEqual(new int[2] { 1, 2 }, instance.doubles); CheckEqual(new int[] { 1, 2, 3, 4, 5, }, instance.collection); CheckEqual(new int[] { 1, 2, 3 }, instance.bakedList); CheckEqual(new Dictionary() { {"1", 'c'}, {"-2", 'p'}, {"5", 'f'}, }, instance.dict); CheckEqual(0, failures.Count); } public void FromLuaTable_Partial() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", }, }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(1, table.RowCount); var instance = table.GetRow(0); CheckEqual(new Tuple(0, null), instance.AandB); CheckEqual(11, instance.composite_element1); CheckEqual("goodbye", instance.composite_element2); CheckEqual(new DateTime(1, 1, 1, 0, 0, 0), instance.date); CheckEqual(new int[3] { 0, 0, 0 }, instance.triples); CheckEqual(new int[2] { 0, 0 }, instance.doubles); CheckEqual(new int[] { }, instance.collection); CheckEqual(new int[] { }, instance.bakedList); CheckEqual(new Dictionary() {}, instance.dict); CheckEqual(0, failures.Count); } public void FromLuaTable_BadDataType() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { { composite_element1 = ""hello"", composite_element2 = ""goodbye"", }, }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(1, table.RowCount); var instance = table.GetRow(0); CheckEqual(new Tuple(0, null), instance.AandB); CheckEqual(0, instance.composite_element1); CheckEqual("goodbye", instance.composite_element2); CheckEqual(new DateTime(1, 1, 1, 0, 0, 0), instance.date); CheckEqual(new int[3] { 0, 0, 0 }, instance.triples); CheckEqual(new int[2] { 0, 0 }, instance.doubles); CheckEqual(new int[] { }, instance.collection); CheckEqual(new int[] { }, instance.bakedList); CheckEqual(new Dictionary() { }, instance.dict); CheckEqual(new[] { @"error : Deserializing composite_element1 failed with " + @"""Input string was not in a correct format.""." }, failures); } public void ToLuaTable_WhitespaceisQ() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; instance1.dict = new Dictionary() { {"1", 'c'}, {"5", 'f'}, {"-2", 'p'} }; var lua = table.SerializeToLuaTable(0, "Q"); var expected = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { [ ""1"" ] = ""c"", [ ""5"" ] = ""f"", [ ""-2"" ] = ""p"", }, }, }".Replace(" ", "Q"); CheckEqual(expected, lua); } public void ToLuaTable_CurrIndent() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; instance1.dict = new Dictionary() { {"1", 'c'}, {"5", 'f'}, {"-2", 'p'} }; var lua = table.SerializeToLuaTable(2); var expected = @" SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { [ ""1"" ] = ""c"", [ ""5"" ] = ""f"", [ ""-2"" ] = ""p"", }, }, }"; CheckEqual(expected, lua); } public void ToLuaTable_MultiRow() { SampleClassTable table = new SampleClassTable(); { var instance = table.NewRow(); instance.AandB = new Tuple(10, "hello"); instance.collection = new List() { 1, 2, 3, 4, 5, }; instance.composite_element1 = 11; instance.composite_element2 = "goodbye"; instance.date = new DateTime(1999, 12, 31, 13, 0, 0); instance.triples = new int[3] { 4, 7, 12 }; instance.doubles = new int[2] { 1, 2 }; instance.bakedList = new List { 1, 2, 3 }; instance.dict = new Dictionary() { {"1", 'c'}, {"5", 'f'}, {"-2", 'p'} }; } { var instance = table.NewRow(); instance.AandB = new Tuple(13, "sticks"); instance.collection = new List() { 6, 7, 8, 9, 0, }; instance.composite_element1 = 12; instance.composite_element2 = "sin"; instance.date = new DateTime(1899, 12, 10, 13, 0, 0); instance.triples = new int[3] { 3, 6, 10 }; instance.doubles = new int[2] { 3, 4 }; instance.bakedList = new List { 4, 5, }; instance.dict = new Dictionary() { {"2", 'a'}, {"3", 'b'}, {"4", 'c'} }; } var lua = table.SerializeToLuaTable(); var expected = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { [ ""1"" ] = ""c"", [ ""5"" ] = ""f"", [ ""-2"" ] = ""p"", }, }, { composite_element1 = ""12"", composite_element2 = ""sin"", date = ""10/12/1899 13:00:00"", --Hi! AandB_Item1 = ""13"", AandB_Item2 = ""sticks"", triples = { ""3"", ""6"", ""10"", }, doubles = { ""3"", ""4"", }, collection = { ""6"", ""7"", ""8"", ""9"", ""0"", }, bakedList = { ""4"", ""5"", }, dict = { [ ""2"" ] = ""a"", [ ""3"" ] = ""b"", [ ""4"" ] = ""c"", }, }, }"; CheckEqual(expected, lua); } public void FromLuaTable_MultiRow() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = {""4"", ""7"", ""12""}, doubles = {""1"", ""2""}, collection = {""1"", ""2"", ""3"", ""4"", ""5""}, bakedList = {""1"", ""2"", ""3""}, }, { composite_element1 = ""12"", composite_element2 = ""sin"", date = ""10/12/1899 13:00:00"", AandB_Item1 = ""13"", AandB_Item2 = ""sticks"", triples = {""3"", ""6"", ""10""}, doubles = {""3"", ""4""}, collection = {""6"", ""7"", ""8"", ""9"", ""0""}, bakedList = {""4"", ""5""}, }, }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(2, table.RowCount); var instance = table.GetRow(0); CheckEqual(new Tuple(10, "hello"), instance.AandB); CheckEqual(11, instance.composite_element1); CheckEqual("goodbye", instance.composite_element2); CheckEqual(new DateTime(1999, 12, 31, 13, 0, 0), instance.date); CheckEqual(new int[3] { 4, 7, 12 }, instance.triples); CheckEqual(new int[2] { 1, 2 }, instance.doubles); CheckEqual(new int[] { 1, 2, 3, 4, 5, }, instance.collection); instance = table.GetRow(1); CheckEqual(new Tuple(13, "sticks"), instance.AandB); CheckEqual(12, instance.composite_element1); CheckEqual("sin", instance.composite_element2); CheckEqual(new DateTime(1899, 12, 10, 13, 0, 0), instance.date); CheckEqual(new int[3] { 3, 6, 10, }, instance.triples); CheckEqual(new int[2] { 3, 4 }, instance.doubles); CheckEqual(new int[] { 6, 7, 8, 9, 0, }, instance.collection); CheckEqual(0, failures.Count); } public void ToLuaTable_MultilineString() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello\r\ntraveller"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; var lua = table.SerializeToLuaTable(2); var expected = @" SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = [[hello traveller]], triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { }, }, }"; CheckEqual(expected, lua); } public void ToLuaTable_MultilineString_EscapedBrackets() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.AandB = new Tuple(10, "hello\r\n[[traveller]]"); instance1.collection = new List() { 1, 2, 3, 4, 5, }; instance1.composite_element1 = 11; instance1.composite_element2 = "goodbye"; instance1.date = new DateTime(1999, 12, 31, 13, 0, 0); instance1.triples = new int[3] { 4, 7, 12 }; instance1.doubles = new int[2] { 1, 2 }; instance1.bakedList = new List { 1, 2, 3 }; var lua = table.SerializeToLuaTable(2); var expected = @" SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = [=[hello [[traveller]]]=], triples = { ""4"", ""7"", ""12"", }, doubles = { ""1"", ""2"", }, collection = { ""1"", ""2"", ""3"", ""4"", ""5"", }, bakedList = { ""1"", ""2"", ""3"", }, dict = { }, }, }"; CheckEqual(expected, lua); } public void CopyToBuffer() { SampleClassTable tableOriginal = new SampleClassTable(); var serialized = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = {""4"", ""7"", ""12""}, doubles = {""1"", ""2"" }, collection = {""1"", ""2"", ""3"", ""4"", ""5""}, bakedList = {""1"", ""2"", ""3""}, }, { composite_element1 = ""12"", composite_element2 = ""sin"", date = ""10/12/1899 13:00:00"", --Hi! AandB_Item1 = ""13"", AandB_Item2 = ""sticks"", triples = {""3"", ""6"", ""10""}, doubles = {""3"", ""4"" }, collection = {""6"", ""7"", ""8"", ""9"", ""0""}, bakedList = {""4"", ""5""}, }, }"; var failures = tableOriginal.LoadFromLuaTable(serialized); var table = new SampleClassTable(); tableOriginal.CopyBuffersTo(ref table); CheckEqual(2, table.RowCount); CheckEqual(2, tableOriginal.RowCount); var instance = table.GetRow(0); var instanceOriginal = tableOriginal.GetRow(0); instanceOriginal.AandB = new Tuple(999, "poop"); CheckEqual(new Tuple(10, "hello"), instance.AandB); instanceOriginal.composite_element1 = 999; CheckEqual(11, instance.composite_element1); instanceOriginal.composite_element2 = "poop"; CheckEqual("goodbye", instance.composite_element2); instanceOriginal.date = DateTime.MaxValue; CheckEqual(new DateTime(1999, 12, 31, 13, 0, 0), instance.date); instanceOriginal.triples = new int[] { 999, 999, 999, }; CheckEqual(new int[3] { 4, 7, 12 }, instance.triples); instanceOriginal.doubles = new int[] { 999, 999 }; CheckEqual(new int[2] { 1, 2 }, instance.doubles); instanceOriginal.collection.Clear(); CheckEqual(new int[] { 1, 2, 3, 4, 5, }, instance.collection); instanceOriginal.bakedList.Clear(); CheckEqual(new int[] { 1, 2, 3, }, instance.bakedList); instance = table.GetRow(1); instanceOriginal = tableOriginal.GetRow(1); instanceOriginal.AandB = new Tuple(999, "poop"); CheckEqual(new Tuple(13, "sticks"), instance.AandB); instanceOriginal.composite_element1 = 999; CheckEqual(12, instance.composite_element1); instanceOriginal.composite_element2 = "poop"; CheckEqual("sin", instance.composite_element2); instanceOriginal.date = DateTime.MaxValue; CheckEqual(new DateTime(1899, 12, 10, 13, 0, 0), instance.date); instanceOriginal.triples = new int[] { 999, 999, 999, }; CheckEqual(new int[3] { 3, 6, 10, }, instance.triples); instanceOriginal.doubles = new int[] { 999, 999 }; CheckEqual(new int[2] { 3, 4 }, instance.doubles); instanceOriginal.collection.Clear(); CheckEqual(new int[] { 6, 7, 8, 9, 0, }, instance.collection); instanceOriginal.bakedList.Clear(); CheckEqual(new int[] { 4, 5, }, instance.bakedList); CheckEqual(0, failures.Count); } public void LoadFromLuaTableRuntimeError() { SampleClassTable table = new SampleClassTable(); var serialized = "error()"; CheckThrow(typeof(Exception)); table.LoadFromLuaTable(serialized); } public void LoadFromLuaTableSyntaxError() { SampleClassTable table = new SampleClassTable(); var serialized = "7 = 'hi'"; CheckThrow(typeof(Exception)); table.LoadFromLuaTable(serialized); } public void LoadFromLuaTable_NotATable() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = 7"; CheckThrow(typeof(Exception)); table.LoadFromLuaTable(serialized); } public void LoadFromLuaTable_NonIntegerIndex() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { ['1'] = { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = {""4"", ""7"", ""12""}, doubles = {""1"", ""2""}, collection = {""1"", ""2"", ""3"", ""4"", ""5""}, bakedList = {""1"", ""2"", ""3""}, dict = { [ ""1"" ] = ""c"", [ [[5]] ] = ""f"", [ [=[-2]=] ] = ""p""}, }, }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(1, failures.Count); CheckEqualRegex("which is not a number", failures[0]); } public void LoadFromLuaTable_NonTableValue() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { 'foo' }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(1, failures.Count); CheckEqualRegex("not a table type", failures[0]); } public void LoadFromLuaTable_FromTableWithMetatable() { SampleClassTable table = new SampleClassTable(); var serialized = @"SampleClass = { { composite_element1 = ""11"", composite_element2 = ""goodbye"", date = ""31/12/1999 13:00:00"", --Hi! AandB_Item1 = ""10"", AandB_Item2 = ""hello"", triples = setmetatable({'4', '7', '12'}, {}), doubles = {""1"", ""2""}, collection = {""1"", ""2"", ""3"", ""4"", ""5""}, bakedList = {""1"", ""2"", ""3""}, dict = { [ ""1"" ] = ""c"", [ [[5]] ] = ""f"", [ [=[-2]=] ] = ""p""}, }, }"; var failures = table.LoadFromLuaTable(serialized); CheckEqual(0, failures.Count); CheckEqual(new int[3] { 4, 7, 12 }, table.GetRow(0).triples); } public class UpdateCapacity : UnitTestSharp.TestFixture { public void NoChange() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 2, 3 }; CheckEqual(1, table.RowCount); table.UpdateCapacity(0); CheckEqual(1, table.RowCount); CheckEqual(new int[] {1, 2, 3}, instance1.triples); } public void Increment() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 2, 3 }; CheckEqual(1, table.RowCount); table.UpdateCapacity(1); CheckEqual(2, table.RowCount); CheckEqual(new int[] { 1, 2, 3 }, instance1.triples); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(1).triples); } public void AddLotsAtOnce() { SampleClassTable table = new SampleClassTable(); table.UpdateCapacity(2); table.UpdateCapacity(4); CheckEqual(6, table.RowCount); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(0).triples); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(1).triples); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(2).triples); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(3).triples); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(4).triples); CheckEqual(new int[] { 0, 0, 0 }, table.GetRow(5).triples); } public void Decrement() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 2, 3 }; CheckEqual(1, table.RowCount); table.UpdateCapacity(-1); CheckEqual(0, table.RowCount); } public void RemoveTooMany() { SampleClassTable table = new SampleClassTable(); table.NewRow(); CheckThrow(typeof(Exception)); table.UpdateCapacity(-2); } public void RemoveLotsAtOnce() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 2, 3 }; table.UpdateCapacity(5); CheckEqual(6, table.RowCount); table.UpdateCapacity(-5); CheckEqual(1, table.RowCount); CheckEqual(new int[] { 1, 2, 3 }, table.GetRow(0).triples); } } public void Clear() { SampleClassTable table = new SampleClassTable(); table.UpdateCapacity(6); CheckEqual(6, table.RowCount); table.Clear(); CheckEqual(0, table.RowCount); } public void ClearEmpty() { SampleClassTable table = new SampleClassTable(); table.Clear(); CheckEqual(0, table.RowCount); } public void DeleteRows() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 0, 0 }; var instance2 = table.NewRow(); instance2.triples = new int[] { 2, 0, 0 }; var instance3 = table.NewRow(); instance3.triples = new int[] { 3, 0, 0 }; CheckEqual(3, table.RowCount); CheckEqual(new int[] { 1, 0, 0 }, table.GetRow(0).triples); CheckEqual(new int[] { 2, 0, 0 }, table.GetRow(1).triples); CheckEqual(new int[] { 3, 0, 0 }, table.GetRow(2).triples); table.DeleteRows(new[] { instance3, instance1 }); CheckEqual(1, table.RowCount); CheckEqual(new int[] { 2, 0, 0 }, table.GetRow(0).triples); } public void DeleteRowsEmpty() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 0, 0 }; var instance2 = table.NewRow(); instance2.triples = new int[] { 2, 0, 0 }; var instance3 = table.NewRow(); instance3.triples = new int[] { 3, 0, 0 }; CheckEqual(3, table.RowCount); CheckEqual(new int[] { 1, 0, 0 }, table.GetRow(0).triples); CheckEqual(new int[] { 2, 0, 0 }, table.GetRow(1).triples); CheckEqual(new int[] { 3, 0, 0 }, table.GetRow(2).triples); table.DeleteRows(new SampleClass[] {}); CheckEqual(3, table.RowCount); CheckEqual(new int[] { 1, 0, 0 }, table.GetRow(0).triples); CheckEqual(new int[] { 2, 0, 0 }, table.GetRow(1).triples); CheckEqual(new int[] { 3, 0, 0 }, table.GetRow(2).triples); } public void DeleteRow() { SampleClassTable table = new SampleClassTable(); var instance1 = table.NewRow(); instance1.triples = new int[] { 1, 0, 0 }; var instance2 = table.NewRow(); instance2.triples = new int[] { 2, 0, 0 }; var instance3 = table.NewRow(); instance3.triples = new int[] { 3, 0, 0 }; CheckEqual(3, table.RowCount); CheckEqual(new int[] { 1, 0, 0 }, table.GetRow(0).triples); CheckEqual(new int[] { 2, 0, 0 }, table.GetRow(1).triples); CheckEqual(new int[] { 3, 0, 0 }, table.GetRow(2).triples); table.DeleteRow(instance2); CheckEqual(2, table.RowCount); CheckEqual(new int[] { 1, 0, 0 }, table.GetRow(0).triples); CheckEqual(new int[] { 3, 0, 0 }, table.GetRow(1).triples); } public void ColumnCount() { SampleClassTable table = new SampleClassTable(); for (int i = 0; i < table.ColumnCount; ++i) { // If it doesn't throw, we're successful. table.GetDefaultObjectByIndex(i); } CheckThrow(typeof(Exception)); table.GetDefaultObjectByIndex(table.ColumnCount); } public void GetEnumeratorTest() { var table = new SampleClassTable(); var enum1 = table.GetEnumerator(); var enum2 = (table as System.Collections.IEnumerable).GetEnumerator(); while(enum1.MoveNext() && enum2.MoveNext()) { CheckEqual(enum1.Current, enum2.Current); } CheckFalse(enum1.MoveNext()); CheckFalse(enum2.MoveNext()); } } }