コード例 #1
0
        public void NameTable_can_save_and_load()
        {
            StringTable stringTable = new StringTable();

            StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable);

            NameTable nameTable = new NameTable('.', stringTable);

            NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder);

            nameTableBuilder.GetOrAdd("a.b.c");
            nameTableBuilder.GetOrAdd("a.b.d.e");
            nameTableBuilder.GetOrAdd("a.f.g.h");

            stringTable.SaveToFile(TemporaryDirectory, $"{nameof(StringTable)}.txt");
            nameTable.SaveToFile(TemporaryDirectory, $"{nameof(NameTable)}.bin");

            StringTable stringTable2 = new StringTable();
            NameTable   nameTable2   = new NameTable('.', stringTable2);

            stringTable2.LoadFromFile(TemporaryDirectory, $"{nameof(StringTable)}.txt");
            nameTable2.LoadFromFile(TemporaryDirectory, $"{nameof(NameTable)}.bin");

            XAssert.AreEqual(8, nameTable2.Count);
            XAssert.AreEqual("a", nameTable2.GetText(nameTable2.Ids.First()));
            XAssert.AreEqual("a.f.g.h", nameTable2.GetText(nameTable2.Ids.Last()));
        }
コード例 #2
0
        public void NameTable_can_store_three_complex_elements()
        {
            StringTable stringTable = new StringTable();

            StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable);

            NameTable nameTable = new NameTable('.', stringTable);

            NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder);

            NameId id  = nameTableBuilder.GetOrAdd("a.b.c");
            NameId id2 = nameTableBuilder.GetOrAdd("a.b.d.e");
            NameId id3 = nameTableBuilder.GetOrAdd("a.f.g.h");

            XAssert.IsFalse(id.Equals(id2));
            XAssert.IsFalse(id.Equals(id3));
            XAssert.IsFalse(id2.Equals(id3));
            XAssert.AreEqual("a.b.c", nameTable.GetText(id));
            XAssert.AreEqual(5, nameTable.Length(id));
            XAssert.AreEqual("a.b.d.e", nameTable.GetText(id2));
            XAssert.AreEqual(7, nameTable.Length(id2));
            XAssert.AreEqual("a.f.g.h", nameTable.GetText(id3));
            XAssert.AreEqual(7, nameTable.Length(id3));
            XAssert.AreEqual(8, nameTable.Count);
            XAssert.AreEqual(8, nameTable.Ids.Count());
        }
コード例 #3
0
        public void NameTable_can_store_one_complex_element()
        {
            StringTable stringTable = new StringTable();

            StringTable.CachingBuilder stringTableBuilder = new StringTable.CachingBuilder(stringTable);

            NameTable nameTable = new NameTable('.', stringTable);

            NameTable.Builder nameTableBuilder = new NameTable.Builder(nameTable, stringTableBuilder);

            NameId id  = nameTableBuilder.GetOrAdd("a.b");
            NameId id2 = nameTableBuilder.GetOrAdd("a.b");

            XAssert.IsTrue(id.Equals(id2));
            XAssert.AreEqual("a.b", nameTable.GetText(id));
            XAssert.AreEqual(3, nameTable.Length(id));
            XAssert.AreEqual(2, nameTable.Count);
            XAssert.AreEqual(2, nameTable.Ids.Count());
        }