public void TestMaxItems() { int maxId = 5000; int[] maxNumItems = { 25, 50, 20, 100, 15, 500, 10, 1000, 5, 1024, 2 }; int[,] count = new int[maxNumItems.Length, maxId]; AllocOnlyTestLoader loader = new AllocOnlyTestLoader(maxId); BigNestedIntArray[] nestedArray = new BigNestedIntArray[maxNumItems.Length]; for(int i = 0 ; i < maxNumItems.Length; i++) { for(int id = 0; id < maxId; id++) { int cnt = id % 2000; loader.addSize(id, cnt); count[i, id] = cnt; } nestedArray[i] = new BigNestedIntArray(); nestedArray[i].setMaxItems(maxNumItems[i]); nestedArray[i].load(maxId, loader); loader.reset(); for(int id = 0; id < maxId; id++) { bool failed = false; for(int data = 0; data < count[i, id]; data++) { if(nestedArray[i].addData(id, data)) { if(!failed && (data + 1 > maxNumItems[i])) { failed = true; Assert.AreEqual(data, maxNumItems[i], "maxItems"); } } } } } }
public void TestAllocThenAddData() { int maxId = 5000; int[] maxNumItems = { 25, 50, 20, 100, 15, 500, 10, 1000, 5, 1024, 2 }; int[,] count = new int[maxNumItems.Length, maxId]; AllocOnlyTestLoader loader = new AllocOnlyTestLoader(maxId); BigNestedIntArray[] nestedArray = new BigNestedIntArray[maxNumItems.Length]; for(int i = 0 ; i < maxNumItems.Length; i++) { for(int id = 0; id < maxId; id++) { int cnt = id % (maxNumItems[i] + 1); loader.addSize(id, cnt); count[i, id] = cnt; } nestedArray[i] = new BigNestedIntArray(); nestedArray[i].load(maxId, loader); loader.reset(); for(int id = 0; id < maxId; id++) { for(int data = 0; data < count[i, id]; data++) { nestedArray[i].addData(id, data); } } } for(int i = 0 ; i < maxNumItems.Length; i++) { int[] buf = new int[1024]; for(int id = 0; id < maxId; id++) { int cnt = nestedArray[i].getData(id, buf); Assert.AreEqual(count[i, id], cnt, "count[" + i + "," + id + "]"); if(cnt > 0) { for(int val = 0; val < cnt; val++) { Assert.AreEqual(val, buf[val], "item[" + i + "," + id + "," + val + "]"); } } } } }