/// <summary> /// check the following operations /// (1) put /// (2) remove & put /// (3) remove /// (4) remove & put again /// </summary> private static void Check(TestLightWeightCache.LightWeightCacheTestCase test) { //check put Print(" check put .................. "); for (int i = 0; i < test.data.Size() / 2; i++) { test.Put(test.data.Get(i)); } for (int i_1 = 0; i_1 < test.data.Size(); i_1++) { test.Put(test.data.Get(i_1)); } Println("DONE " + test.Stat()); //check remove and put Print(" check remove & put ......... "); for (int j = 0; j < 10; j++) { for (int i_2 = 0; i_2 < test.data.Size() / 2; i_2++) { int r = ran.Next(test.data.Size()); test.Remove(test.data.Get(r)); } for (int i_3 = 0; i_3 < test.data.Size() / 2; i_3++) { int r = ran.Next(test.data.Size()); test.Put(test.data.Get(r)); } } Println("DONE " + test.Stat()); //check remove Print(" check remove ............... "); for (int i_4 = 0; i_4 < test.data.Size(); i_4++) { test.Remove(test.data.Get(i_4)); } Assert.Equal(0, test.cache.Size()); Println("DONE " + test.Stat()); //check remove and put again Print(" check remove & put again ... "); for (int j_1 = 0; j_1 < 10; j_1++) { for (int i_2 = 0; i_2 < test.data.Size() / 2; i_2++) { int r = ran.Next(test.data.Size()); test.Remove(test.data.Get(r)); } for (int i_3 = 0; i_3 < test.data.Size() / 2; i_3++) { int r = ran.Next(test.data.Size()); test.Put(test.data.Get(r)); } } Println("DONE " + test.Stat()); long s = (Time.Now() - starttime) / 1000L; Println("total time elapsed=" + s + "s\n"); }
private static void CheckSizeLimit(int sizeLimit, int datasize, int modulus) { TestLightWeightCache.LightWeightCacheTestCase test = new TestLightWeightCache.LightWeightCacheTestCase (sizeLimit, sizeLimit, 1L << 32, 1L << 32, datasize, modulus); // keep putting entries and check size limit Print(" check size ................. "); for (int i = 0; i < test.data.Size(); i++) { test.cache.Put(test.data.Get(i)); Assert.True(test.cache.Size() <= sizeLimit); } Println("DONE " + test.Stat()); }