public void WriteWordTest2_Sequential() { ICacheController <int> cacheController = CreateController(); int i = 0; do { // write -> read string s = string.Format("1st{0:000}", i); Word word = new Word(i, Convert(s)); cacheController.WriteWord(i, word); Word wordBack = cacheController.ReadWord(i); Assert.AreEqual(word.Tag, wordBack.Tag); Assert.IsTrue(word.Buffer.SequenceEqual(wordBack.Buffer)); // update -> read s = string.Format("2nd{0:000}", i); Word wordSecond = new Word(i, Convert(s)); cacheController.WriteWord(i, wordSecond); Word wordBackSecond = cacheController.ReadWord(i); Assert.AreEqual(wordSecond.Tag, wordBackSecond.Tag); } while (!databaseStorage_.EOF(++i)); }
static void Main(string[] args) { ICacheController <int> cacheController = CreateController(); // write -> read byte[] bytes42 = Encoding.ASCII.GetBytes("first42"); byte[] bytes43 = Encoding.ASCII.GetBytes("first43"); Word word42 = new Word(42, bytes42); Word word43 = new Word(43, bytes43); cacheController.WriteWord(42, word42); Word wordBack42 = cacheController.ReadWord(42); cacheController.WriteWord(43, word43); Word wordBack43 = cacheController.ReadWord(43); // update -> read byte[] byteSecond42 = Encoding.ASCII.GetBytes("second42"); byte[] byteSecond43 = Encoding.ASCII.GetBytes("second43"); Word wordSecond42 = new Word(42, bytes42); Word wordSecond43 = new Word(43, bytes43); cacheController.WriteWord(42, word42); Word wordBackSecond42 = cacheController.ReadWord(42); cacheController.WriteWord(43, word43); Word wordBackSecond43 = cacheController.ReadWord(43); }
public void ReadWordTest3_Sequential() { ICacheController <int> cacheController = CreateController(); // if line consists from n words then word0...wordn-1 will be not chached when word0 requested first time // but subsequent reading of word1..wordn-1 will hit for (int i = kMinSequentialUserID; i <= kMaxSequentialUserID; ++i) { Word word = cacheController.ReadWord(i); if (i % kWordsInLine == 1) { Assert.AreEqual(word.isCached, false); // miss for word0 } else { Assert.AreEqual(word.isCached, true); // hit for word1..wordn-1 } } Word word291 = cacheController.ReadWord(291); Assert.IsTrue(word291.IsEmpty); Word word999 = cacheController.ReadWord(999); Assert.AreEqual(word999.isCached, true); }
public void ReadWordTest4_Sequential() { ICacheController <int> cacheController = CreateController(); int i = 0; do { Word word = cacheController.ReadWord(i); if (word.IsEmpty) { continue; } if (i % kWordsInLine == 1) { Assert.AreEqual(word.isCached, false); // miss word = cacheController.ReadWord(i); Assert.AreEqual(word.isCached, true); // hit second time } else { Assert.AreEqual(word.isCached, true); // hit } } while (!databaseStorage_.EOF(++i)); }
public void ReadWordTest2_Sequential() { ICacheController <int> cacheController = CreateController(); int i = 0; do { Word word = cacheController.ReadWord(i); Word wordHit = cacheController.ReadWord(i); // read hit second time for the same word if (!wordHit.IsEmpty) { Assert.AreEqual(word.Tag, wordHit.Tag); } } while (!databaseStorage_.EOF(++i)); }
public void ReadWordTest1_SelectedTags() { ICacheController <int> cacheController = CreateController(); Word word42 = cacheController.ReadWord(42); Word word42Hit = cacheController.ReadWord(42); // read hit Assert.AreEqual(word42.Tag, word42Hit.Tag); Assert.AreEqual(word42Hit.isCached, true); Word word = cacheController.ReadWord(43); Word wordHit = cacheController.ReadWord(43); // read hit Assert.AreEqual(word.Tag, wordHit.Tag); Assert.AreEqual(wordHit.isCached, true); }
public void WriteWordTest1_SelectedTags() { ICacheController <int> cacheController = CreateController(); // write -> read byte[] bytes42 = Encoding.ASCII.GetBytes("first42"); byte[] bytes43 = Encoding.ASCII.GetBytes("first43"); Word word42 = new Word(42, bytes42); Word word43 = new Word(43, bytes43); cacheController.WriteWord(42, word42); Word wordBack42 = cacheController.ReadWord(42); Assert.AreEqual(word42.Tag, wordBack42.Tag); cacheController.WriteWord(43, word43); Word wordBack43 = cacheController.ReadWord(43); Assert.AreEqual(word43.Tag, wordBack43.Tag); // update -> read byte[] byteSecond42 = Encoding.ASCII.GetBytes("second42"); byte[] byteSecond43 = Encoding.ASCII.GetBytes("second43"); Word wordSecond42 = new Word(42, bytes42); Word wordSecond43 = new Word(43, bytes43); cacheController.WriteWord(42, word42); Word wordBackSecond42 = cacheController.ReadWord(42); Assert.AreEqual(word42.Tag, wordBackSecond42.Tag); cacheController.WriteWord(43, word43); Word wordBackSecond43 = cacheController.ReadWord(43); Assert.AreEqual(word43.Tag, wordBackSecond43.Tag); }
public void ReadWordTest5_FirstRepresentativeZero() { ICacheController <int> cacheController = CreateController(); int linesPerSet_Mod = (int)Math.Pow(2, kLinesDegree) / kNumberOfWays;; // iterate throug all members of class [0] = Z linesPerSet_Mod = Z mod linesPerSet_Mod // rep = representative int rep = kMinSequentialUserID; for (int c = 0, tag = rep + linesPerSet_Mod * c; tag <= kMaxSequentialUserID; ++c, tag = rep + linesPerSet_Mod * c) { Word word = cacheController.ReadWord(tag); Assert.AreEqual(word.SetIndex, c % kNumberOfWays); } }
public void ReadWordTest6_AllRepresentatives() { ICacheController <int> cacheController = CreateController(); int linesPerSet_Mod = (int)Math.Pow(2, kLinesDegree) / kNumberOfWays; // iterate throug all representatives of ring (Z mod linesPerSet_Mod): [0], [1], ..., [linesPerSet_Mod - 1] // rep = representative for (int rep = kMinSequentialUserID; rep < linesPerSet_Mod; ++rep) { // iterate throug all members of class [a] = Z linesPerSet_Mod = Z mod linesPerSet_Mod // [a] = {x: z mod linesPerSet_Mod == a, z E Z} for (int c = 0, tag = rep + linesPerSet_Mod * c; tag <= kMaxSequentialUserID; ++c, tag = rep + linesPerSet_Mod * c) { Word word = cacheController.ReadWord(tag); Assert.AreEqual(word.SetIndex, c % kNumberOfWays); } } }