Ejemplo n.º 1
0
        public void ShouldFindNotSoComplicatedTest()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("一", 0, 100),
                MakeSymbolEntry("国", 50, 20),
                MakeSymbolEntry("五", 55, 5),
                MakeSymbolEntry("中", 60, 10),
                MakeSymbolEntry("猫", 80, 15),
                MakeSymbolEntry("私", 85, 5),
                MakeSymbolEntry("ICantSpeekJapaneese", 56, 2),
                MakeSymbolEntry("KoreanNeither", 58, 2)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Assert.AreEqual("一", lookup.GetSymbolByAddress(1).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(52).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(55).Name);
            Assert.AreEqual("中", lookup.GetSymbolByAddress(64).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(72).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(84).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(94).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(95).Name);
            Assert.AreEqual("ICantSpeekJapaneese", lookup.GetSymbolByAddress(57).Name);
            Assert.AreEqual("KoreanNeither", lookup.GetSymbolByAddress(59).Name);
        }
Ejemplo n.º 2
0
        public void ShouldWorkWithStackedTest()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("一", 0, 50),
                MakeSymbolEntry("国", 50, 50),
                MakeSymbolEntry("五", 65, 35),
                MakeSymbolEntry("中", 70, 30),
                MakeSymbolEntry("猫", 80, 20),
                MakeSymbolEntry("私", 81, 9),
                MakeSymbolEntry("糞", 90, 10)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Assert.AreEqual("一", lookup.GetSymbolByAddress(1).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(52).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(66).Name);
            Assert.AreEqual("中", lookup.GetSymbolByAddress(71).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(80).Name);
            Assert.AreEqual("私", lookup.GetSymbolByAddress(82).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(94).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(99).Name);
            Symbol dummy;

            Assert.IsFalse(lookup.TryGetSymbolByAddress(100, out dummy));
        }
Ejemplo n.º 3
0
        public void ShouldFindSimplyNestedSymbol()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("Big", 0, 100),
                MakeSymbolEntry("Small", 50, 10)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(10).Name);
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(51).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(60).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(61).Name);
        }
Ejemplo n.º 4
0
        public void ShouldHaveImportantViaAddress()
        {
            int symbolNumber = 0;

            var symbols = new List<Symbol>();
            //reverse order according to type importance. This is not optimal, but the actual
            //importance is private to Symbol type.
            foreach(var type in new []{ SymbolType.Function,
                SymbolType.NotSpecified,
                SymbolType.ProcessorSpecific,
                SymbolType.Section,
                SymbolType.Object,
                SymbolType.File })
            {
                foreach(var binding in new []{ SymbolBinding.Global,
                    SymbolBinding.Local,
                    SymbolBinding.ProcessorSpecific,
                    SymbolBinding.Weak })
                {
                    symbols.Add(new Symbol(0, 10, symbolNumber.ToString(), type, binding));
                    symbolNumber++;
                }
            }
            //check every symbol. The symbol in question and all LESS important are added, both in order and in reverse order.
            for(var i = 0; i < symbols.Count; ++i)
            {
                var lookup = new SymbolLookup();
                lookup.InsertSymbols(symbols.Skip(i));
                Assert.AreEqual(symbols[i], lookup.GetSymbolByAddress(5));
                lookup = new SymbolLookup();
                lookup.InsertSymbols(symbols.Skip(i).Reverse());
                Assert.AreEqual(symbols[i], lookup.GetSymbolByAddress(5));
            }
        }
Ejemplo n.º 5
0
        public void ShouldNotDedupliacteIfThereAreTwoDifferentSymbolsWithSameNameAndInterval()
        {
            var symbols1 = new List<Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(20, 35, "三"),
            };
            var symbols2 = new List<Symbol>
            {
                new Symbol(20, 35, "一"),
            };
            var lookup1 = new SymbolLookup();
            var lookup2 = new SymbolLookup();
            lookup1.InsertSymbols(symbols1);
            lookup2.InsertSymbols(symbols2);

            var symbol = symbols1[0];
            Assert.AreNotSame(
                lookup1.GetSymbolsByName(symbol.Name).First(),
                lookup2.GetSymbolsByName(symbol.Name).First(),
                string.Format("Symbol {0} has been deduplicated while it shouldn't.", symbol)
            );
            symbol = symbols1[1];
            Assert.AreNotSame(
                lookup1.GetSymbolByAddress(symbol.Start),
                lookup2.GetSymbolByAddress(symbol.Start),
                string.Format("Symbol {0} has been deduplicated while it shouldn't.", symbol)
            );
        }
Ejemplo n.º 6
0
        public void ShouldNotDedupliacteIfThereAreTwoDifferentSymbolsWithSameNameAndInterval()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(20, 35, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(20, 35, "一"),
            };
            var lookup1 = new SymbolLookup();
            var lookup2 = new SymbolLookup();

            lookup1.InsertSymbols(symbols1);
            lookup2.InsertSymbols(symbols2);

            var symbol = symbols1[0];

            Assert.AreNotSame(
                lookup1.GetSymbolsByName(symbol.Name).First(),
                lookup2.GetSymbolsByName(symbol.Name).First(),
                string.Format("Symbol {0} has been deduplicated while it shouldn't.", symbol)
                );
            symbol = symbols1[1];
            Assert.AreNotSame(
                lookup1.GetSymbolByAddress(symbol.Start),
                lookup2.GetSymbolByAddress(symbol.Start),
                string.Format("Symbol {0} has been deduplicated while it shouldn't.", symbol)
                );
        }
Ejemplo n.º 7
0
        public void ShouldHaveImportantViaAddress()
        {
            int symbolNumber = 0;

            var symbols = new List <Symbol>();

            //reverse order according to type importance. This is not optimal, but the actual
            //importance is private to Symbol type.
            foreach (var type in new [] { SymbolType.Function,
                                          SymbolType.NotSpecified,
                                          SymbolType.ProcessorSpecific,
                                          SymbolType.Section,
                                          SymbolType.Object,
                                          SymbolType.File })
            {
                foreach (var binding in new [] { SymbolBinding.Global,
                                                 SymbolBinding.Local,
                                                 SymbolBinding.ProcessorSpecific,
                                                 SymbolBinding.Weak })
                {
                    symbols.Add(new Symbol(0, 10, symbolNumber.ToString(), type, binding));
                    symbolNumber++;
                }
            }
            //check every symbol. The symbol in question and all LESS important are added, both in order and in reverse order.
            for (var i = 0; i < symbols.Count; ++i)
            {
                var lookup = new SymbolLookup();
                lookup.InsertSymbols(symbols.Skip(i));
                Assert.AreEqual(symbols[i], lookup.GetSymbolByAddress(5));
                lookup = new SymbolLookup();
                lookup.InsertSymbols(symbols.Skip(i).Reverse());
                Assert.AreEqual(symbols[i], lookup.GetSymbolByAddress(5));
            }
        }
Ejemplo n.º 8
0
        public void ShouldFindOneSymbolBoundary()
        {
            var lookup = new SymbolLookup();

            lookup.InsertSymbol("Test", 0x100, 0x10);
            Assert.AreEqual("Test", lookup.GetSymbolByAddress(0x100).Name);
        }
Ejemplo n.º 9
0
        public void ShouldTrimBigSymbol()
        {
            Symbol dummy;
            var    lookup  = new SymbolLookup();
            var    symbols = new List <Symbol>
            {
                MakeSymbolEntry("Large", 0, 10),
                MakeSymbolEntry("Small", 9, 1)
            };

            lookup.InsertSymbols(symbols);

            Assert.IsFalse(lookup.TryGetSymbolByAddress(10, out dummy));
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(9).Name);
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(8).Name);
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(0).Name);
        }
Ejemplo n.º 10
0
        public void ShouldFindDoubleCut()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("Big", 0, 100),
                MakeSymbolEntry("Alice", 10, 20),
                MakeSymbolEntry("Bob", 70, 20)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(15).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(35).Name);
            Assert.AreEqual("Bob", lookup.GetSymbolByAddress(75).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(95).Name);
        }
Ejemplo n.º 11
0
        public void ShouldFindRecursivelyNestedSymbol()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("Big", 0, 100),
                MakeSymbolEntry("Average", 40, 20),
                MakeSymbolEntry("Small", 50, 5)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Assert.AreEqual("Big", lookup.GetSymbolByAddress(10).Name);
            Assert.AreEqual("Average", lookup.GetSymbolByAddress(41).Name);
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(51).Name);
            Assert.AreEqual("Average", lookup.GetSymbolByAddress(55).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(60).Name);
        }
Ejemplo n.º 12
0
        public void ShouldFindTenSymbols()
        {
            var symbols = Enumerable.Range(1, 10).Select(x => MakeSymbolEntry(x.ToString(), (uint)(x * 10), 5)).ToList();
            var lookup  = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            foreach (var symbol in symbols)
            {
                Assert.AreEqual(symbol.Name, lookup.GetSymbolByAddress(symbol.Start + 2).Name);
            }
        }
        public void ShouldSortedIntervalsHaveExpectedLayout()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(1, 85, "四"),
                new Symbol(2, 70, "国"),
                new Symbol(80, 85, "猫"),
                new Symbol(3, 60, "中"),
                new Symbol(70, 75, "私"),
                new Symbol(4, 15, "五"),
                new Symbol(20, 35, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(5, 25, "糞"),
                new Symbol(40, 82, "二"),
                new Symbol(50, 55, "ICantSpeekJapaneese"),
                new Symbol(45, 50, "ICantSpeekKorean"),
            };
            var expectedSymbols = new List <Symbol>
            {
                new Symbol(0, 5, "一"),
                new Symbol(1, 5, "四"),
                new Symbol(2, 5, "国"),
                new Symbol(3, 5, "中"),
                new Symbol(4, 5, "五"),
                new Symbol(5, 25, "糞"),
                new Symbol(25, 40, "中"),
                new Symbol(25, 35, "三"),
                new Symbol(40, 82, "二"),
                new Symbol(45, 50, "ICantSpeekKorean"),
                new Symbol(50, 55, "ICantSpeekJapaneese"),
                new Symbol(82, 100, "一"),
                new Symbol(82, 85, "猫"),
            };
            var addressesToQuery = new List <uint> {
                0, 1, 2, 3, 4, 10, 37, 30, 42, 47, 53, 90, 83
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(
                expectedSymbols,
                addressesToQuery.Select(address => lookup.GetSymbolByAddress(address))
                );
        }
Ejemplo n.º 14
0
        public void ShouldFindZeroLenghtSymbol()
        {
            var symbols = new List <Symbol>
            {
                new Symbol(0, 75, "一"),
                new Symbol(50, 75, "三"),
                new Symbol(75, 75, "二"),
                new Symbol(75, 100, "一"),
                new Symbol(75, 99, "三"),
            };
            var addressesToQuery = new List <uint> {
                5, 60, 75, 99, 76
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            CollectionAssert.AreEqual(symbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
Ejemplo n.º 15
0
        public void ShouldFindNestedDeeper()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("First", 0, 100),
                MakeSymbolEntry("Second", 10, 80),
                MakeSymbolEntry("Third", 20, 60),
                MakeSymbolEntry("Fourth", 30, 40)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Assert.AreEqual("First", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Second", lookup.GetSymbolByAddress(15).Name);
            Assert.AreEqual("Third", lookup.GetSymbolByAddress(25).Name);
            Assert.AreEqual("Fourth", lookup.GetSymbolByAddress(35).Name);
            Assert.AreEqual("Third", lookup.GetSymbolByAddress(75).Name);
            Assert.AreEqual("Second", lookup.GetSymbolByAddress(85).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(95).Name);
        }
Ejemplo n.º 16
0
 public void ShouldMergeTrimEndAndBeginning()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 50, "一"),
         new Symbol(50, 100, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(30, 70, "二"),
     };
     var expectedSymbols = new List<Symbol>
     {
         new Symbol(0, 30, "一"),
         new Symbol(30, 70, "二"),
         new Symbol(70, 100, "三"),
     };
     var addressesToQuery = new List<uint>{25, 35, 75};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
 }
Ejemplo n.º 17
0
        public void ShouldNotCrashOnInsertDoubledSymbol()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("一", 0, 100),
                MakeSymbolEntry("二", 0, 100),
                MakeSymbolEntry("三", 100, 15),
                MakeSymbolEntry("四", 100, 15),
                MakeSymbolEntry("国", 10, 15),
                MakeSymbolEntry("五", 10, 15),
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            Symbol dummySymbol;

            foreach (var symbol in symbols)
            {
                lookup.GetSymbolsByName(symbol.Name);
                lookup.GetSymbolByAddress(symbol.Start);
                lookup.TryGetSymbolByAddress(symbol.End, out dummySymbol);
            }
        }
Ejemplo n.º 18
0
        public void ShouldFindMatroska()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("First", 90, 10),
                MakeSymbolEntry("Second", 80, 20),
                MakeSymbolEntry("Third", 70, 30),
                MakeSymbolEntry("Fourth", 60, 40),
                MakeSymbolEntry("Fifth", 85, 5),
                MakeSymbolEntry("Sixth", 40, 20),
                MakeSymbolEntry("Seventh", 0, 100)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Assert.AreEqual("Seventh", lookup.GetSymbolByAddress(0).Name);
            Assert.AreEqual("Sixth", lookup.GetSymbolByAddress(45).Name);
            Assert.AreEqual("Fifth", lookup.GetSymbolByAddress(85).Name);
            Assert.AreEqual("Fourth", lookup.GetSymbolByAddress(65).Name);
            Assert.AreEqual("Third", lookup.GetSymbolByAddress(75).Name);
            Assert.AreEqual("Second", lookup.GetSymbolByAddress(80).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(90).Name);
        }
Ejemplo n.º 19
0
        public void ShouldWorkWithLongSeriesAndNesting()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("Large", 0, 10),
                MakeSymbolEntry("First", 3, 3),
                MakeSymbolEntry("Small", 4, 1),
                MakeSymbolEntry("Last", 6, 1)
            };

            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Symbol dummy;

            Assert.IsFalse(lookup.TryGetSymbolByAddress(10, out dummy));
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(9).Name);
            Assert.AreEqual("Last", lookup.GetSymbolByAddress(6).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(4).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(3).Name);
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(2).Name);
        }
Ejemplo n.º 20
0
        public void ShouldTrimBigSymbol()
        {
            Symbol dummy;
            var lookup = new SymbolLookup();
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("Large", 0, 10),
                MakeSymbolEntry("Small", 9, 1)
            };
            lookup.InsertSymbols(symbols);

            Assert.IsFalse(lookup.TryGetSymbolByAddress(10, out dummy));
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(9).Name);
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(8).Name);
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(0).Name);
        }
Ejemplo n.º 21
0
        public void ShouldFindNestedAndDoubleCut()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("Big", 0, 100),
                MakeSymbolEntry("Alice", 10, 30),
                MakeSymbolEntry("Small1", 20, 5),
                MakeSymbolEntry("Small2", 30, 5),
                MakeSymbolEntry("Bob", 60, 30),
                MakeSymbolEntry("Small3", 70, 5)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Assert.AreEqual("Big", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(15).Name);
            Assert.AreEqual("Small1", lookup.GetSymbolByAddress(22).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(26).Name);
            Assert.AreEqual("Small2", lookup.GetSymbolByAddress(31).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(36).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(41).Name);
            Assert.AreEqual("Bob", lookup.GetSymbolByAddress(61).Name);
            Assert.AreEqual("Small3", lookup.GetSymbolByAddress(71).Name);
            Assert.AreEqual("Bob", lookup.GetSymbolByAddress(76).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(91).Name);
        }
        public void ShouldFavorUnempty()
        {
            var symbols = new List <Symbol>
            {
                new Symbol(0, 10, "Unempty"),
                new Symbol(0, 10, ""),
                new Symbol(10, 20, "Other"),
            };

            var expectedSymbols = new List <Symbol>
            {
                new Symbol(0, 10, "Unempty"),
                new Symbol(10, 20, "Other"),
            };

            var addressesToQuery = new List <uint> {
                0, 10
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
Ejemplo n.º 23
0
        public void ShouldFindComplicatedFromSingleInsertsTest()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("一", 0, 100),
                MakeSymbolEntry("二", 10, 40),
                MakeSymbolEntry("三", 15, 15),
                MakeSymbolEntry("四", 30, 15),
                MakeSymbolEntry("五", 55, 5),
                MakeSymbolEntry("中", 60, 10),
                MakeSymbolEntry("国", 50, 20),
                MakeSymbolEntry("猫", 80, 15),
                MakeSymbolEntry("私", 85, 5),
                MakeSymbolEntry("糞", 100, 20),
                MakeSymbolEntry("ICantSpeekJapaneese", 56, 2),
                MakeSymbolEntry("KoreanNeither", 58, 2)
            };
            var lookup = new SymbolLookup();

            foreach (var symbol in symbols)
            {
                lookup.InsertSymbol(symbol);
            }

            Assert.AreEqual("一", lookup.GetSymbolByAddress(1).Name);
            Assert.AreEqual("二", lookup.GetSymbolByAddress(11).Name);
            Assert.AreEqual("三", lookup.GetSymbolByAddress(16).Name);
            Assert.AreEqual("四", lookup.GetSymbolByAddress(31).Name);
            Assert.AreEqual("二", lookup.GetSymbolByAddress(46).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(52).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(55).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(64).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(72).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(84).Name);
            Assert.AreEqual("私", lookup.GetSymbolByAddress(86).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(94).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(95).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(100).Name);

            Assert.AreEqual("ICantSpeekJapaneese", lookup.GetSymbolByAddress(57).Name);
            Assert.AreEqual("KoreanNeither", lookup.GetSymbolByAddress(59).Name);
        }
Ejemplo n.º 24
0
 public void ShouldFindSimplyNestedSymbol()
 {
     var symbols = new List<Symbol>
     {
         MakeSymbolEntry("Big", 0, 100),
         MakeSymbolEntry("Small", 50, 10)
     };
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols);
     Assert.AreEqual("Big", lookup.GetSymbolByAddress(10).Name);
     Assert.AreEqual("Small", lookup.GetSymbolByAddress(51).Name);
     Assert.AreEqual("Big", lookup.GetSymbolByAddress(60).Name);
     Assert.AreEqual("Big", lookup.GetSymbolByAddress(61).Name);
 }
        public void ShouldZeroLenghtSymbolCutAfterCake()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 50, "一"),
                new Symbol(10, 50, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(50, 50, "二"),
            };
            var expectedSymbols = new List <Symbol>
            {
                new Symbol(0, 50, "一"),
                new Symbol(10, 50, "三"),
                new Symbol(50, 50, "二"),
            };
            var addressesToQuery = new List <uint> {
                0, 15, 50
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
Ejemplo n.º 26
0
        public void ShouldFindComplicatedFromSingleInsertsTest()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("一", 0, 100),
                MakeSymbolEntry("二", 10, 40),
                MakeSymbolEntry("三", 15, 15),
                MakeSymbolEntry("四", 30, 15),
                MakeSymbolEntry("五", 55, 5),
                MakeSymbolEntry("中", 60, 10),
                MakeSymbolEntry("国", 50, 20),
                MakeSymbolEntry("猫", 80, 15),
                MakeSymbolEntry("私", 85, 5),
                MakeSymbolEntry("糞", 100, 20),
                MakeSymbolEntry("ICantSpeekJapaneese", 56, 2),
                MakeSymbolEntry("KoreanNeither", 58, 2)
            };
            var lookup = new SymbolLookup();
            foreach(var symbol in symbols)
            {
                lookup.InsertSymbol(symbol);
            }

            Assert.AreEqual("一", lookup.GetSymbolByAddress(1).Name);
            Assert.AreEqual("二", lookup.GetSymbolByAddress(11).Name);
            Assert.AreEqual("三", lookup.GetSymbolByAddress(16).Name);
            Assert.AreEqual("四", lookup.GetSymbolByAddress(31).Name);
            Assert.AreEqual("二", lookup.GetSymbolByAddress(46).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(52).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(55).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(64).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(72).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(84).Name);
            Assert.AreEqual("私", lookup.GetSymbolByAddress(86).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(94).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(95).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(100).Name);

            Assert.AreEqual("ICantSpeekJapaneese", lookup.GetSymbolByAddress(57).Name);
            Assert.AreEqual("KoreanNeither", lookup.GetSymbolByAddress(59).Name);
        }
Ejemplo n.º 27
0
        public void ShouldFindRecursivelyNestedSymbol()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("Big", 0, 100),
                MakeSymbolEntry("Average", 40, 20),
                MakeSymbolEntry("Small", 50, 5)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Assert.AreEqual("Big", lookup.GetSymbolByAddress(10).Name);
            Assert.AreEqual("Average", lookup.GetSymbolByAddress(41).Name);
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(51).Name);
            Assert.AreEqual("Average", lookup.GetSymbolByAddress(55).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(60).Name);
        }
Ejemplo n.º 28
0
        public void ShouldFindMatroska()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("First", 90, 10),
                MakeSymbolEntry("Second", 80, 20),
                MakeSymbolEntry("Third", 70, 30),
                MakeSymbolEntry("Fourth", 60, 40),
                MakeSymbolEntry("Fifth", 85, 5),
                MakeSymbolEntry("Sixth", 40, 20),
                MakeSymbolEntry("Seventh", 0, 100)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Assert.AreEqual("Seventh", lookup.GetSymbolByAddress(0).Name);
            Assert.AreEqual("Sixth", lookup.GetSymbolByAddress(45).Name);
            Assert.AreEqual("Fifth", lookup.GetSymbolByAddress(85).Name);
            Assert.AreEqual("Fourth", lookup.GetSymbolByAddress(65).Name);
            Assert.AreEqual("Third", lookup.GetSymbolByAddress(75).Name);
            Assert.AreEqual("Second", lookup.GetSymbolByAddress(80).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(90).Name);
        }
Ejemplo n.º 29
0
        public void ShouldFindNestedDeeper()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("First", 0, 100),
                MakeSymbolEntry("Second", 10, 80),
                MakeSymbolEntry("Third", 20, 60),
                MakeSymbolEntry("Fourth", 30, 40)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Assert.AreEqual("First", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Second", lookup.GetSymbolByAddress(15).Name);
            Assert.AreEqual("Third", lookup.GetSymbolByAddress(25).Name);
            Assert.AreEqual("Fourth", lookup.GetSymbolByAddress(35).Name);
            Assert.AreEqual("Third", lookup.GetSymbolByAddress(75).Name);
            Assert.AreEqual("Second", lookup.GetSymbolByAddress(85).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(95).Name);
        }
Ejemplo n.º 30
0
        public void ShouldWorkWithLongSeriesAndNesting()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("Large", 0, 10),
                MakeSymbolEntry("First", 3, 3),
                MakeSymbolEntry("Small", 4, 1),
                MakeSymbolEntry("Last", 6, 1)
            };

            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Symbol dummy;
            Assert.IsFalse(lookup.TryGetSymbolByAddress(10, out dummy));
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(9).Name);
            Assert.AreEqual("Last", lookup.GetSymbolByAddress(6).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Small", lookup.GetSymbolByAddress(4).Name);
            Assert.AreEqual("First", lookup.GetSymbolByAddress(3).Name);
            Assert.AreEqual("Large", lookup.GetSymbolByAddress(2).Name);
        }
        public void ShouldTrimCakeToTopSymbol()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(1, 85, "四"),
                new Symbol(2, 70, "国"),
                new Symbol(3, 60, "中"),
                new Symbol(4, 60, "五"),
                new Symbol(20, 50, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(0, 30, "猫"),
                new Symbol(40, 100, "糞"),
            };
            var expectedSymbols = new List <Symbol> {
                new Symbol(0, 30, "猫"),
                new Symbol(30, 40, "三"),
                new Symbol(40, 100, "糞"),
            };
            var addressesToQuery = new List <uint> {
                10, 37, 80
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
        public void ShouldSplitCakeAfterSecondTower()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(1, 8, "四"),
                new Symbol(20, 40, "国"),
                new Symbol(30, 40, "中"),
                new Symbol(50, 60, "五"),
                new Symbol(50, 55, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(42, 47, "猫"),
                new Symbol(43, 43, "糞"),
            };
            var expectedSymbols = new List <Symbol> {
                new Symbol(0, 42, "一"),
                new Symbol(1, 8, "四"),
                new Symbol(20, 40, "国"),
                new Symbol(30, 40, "中"),
                new Symbol(42, 47, "猫"),
                new Symbol(43, 43, "糞"),
                new Symbol(47, 100, "一"),
                new Symbol(50, 60, "五"),
                new Symbol(50, 55, "三"),
            };
            var addressesToQuery = new List <uint> {
                41, 5, 25, 35, 45, 43, 48, 58, 50
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
        public void ShouldTrimEndAndBeginning2()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(30, 70, "二"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(0, 40, "一"),
                new Symbol(60, 100, "三"),
            };
            var expectedSymbols = new List <Symbol>
            {
                new Symbol(0, 40, "一"),
                new Symbol(40, 60, "二"),
                new Symbol(60, 100, "三"),
            };
            var addressesToQuery = new List <uint> {
                25, 59, 60
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
Ejemplo n.º 34
0
 public void ShouldHaveSlicedSymbolInNameLookup()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(20, 40, "国"),
         new Symbol(30, 40, "中"),
         new Symbol(50, 60, "五"),
         new Symbol(50, 55, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(30, 35, "中"),
     };
     var expectedSymbols = new List<Symbol> {
         new Symbol(20, 30, "国"),
         new Symbol(30, 35, "中"),
         new Symbol(35, 40, "中"),
         new Symbol(50, 60, "五"),
         new Symbol(50, 55, "三"),
     };
     var addressesToQuery = new List<uint>{20, 30, 35, 58, 50};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));        
     var name = expectedSymbols[1].Name;
     Assert.AreEqual(expectedSymbols[1], lookup.GetSymbolsByName(name).ElementAt(0));
     Assert.AreEqual(expectedSymbols[2], lookup.GetSymbolsByName(name).ElementAt(1));
 }
Ejemplo n.º 35
0
        public void ShouldFindNestedAndDoubleCut()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("Big", 0, 100),
                MakeSymbolEntry("Alice", 10, 30),
                MakeSymbolEntry("Small1", 20, 5),
                MakeSymbolEntry("Small2", 30, 5),
                MakeSymbolEntry("Bob", 60, 30),
                MakeSymbolEntry("Small3", 70, 5)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);

            Assert.AreEqual("Big", lookup.GetSymbolByAddress(5).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(15).Name);
            Assert.AreEqual("Small1", lookup.GetSymbolByAddress(22).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(26).Name);
            Assert.AreEqual("Small2", lookup.GetSymbolByAddress(31).Name);
            Assert.AreEqual("Alice", lookup.GetSymbolByAddress(36).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(41).Name);
            Assert.AreEqual("Bob", lookup.GetSymbolByAddress(61).Name);
            Assert.AreEqual("Small3", lookup.GetSymbolByAddress(71).Name);
            Assert.AreEqual("Bob", lookup.GetSymbolByAddress(76).Name);
            Assert.AreEqual("Big", lookup.GetSymbolByAddress(91).Name);
        }
Ejemplo n.º 36
0
 public void ShouldZeroLenghtSymbolCutAfterCake()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 50, "一"),
         new Symbol(10, 50, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(50, 50, "二"),
     };
     var expectedSymbols = new List<Symbol>
     {
         new Symbol(0, 50, "一"),
         new Symbol(10, 50, "三"),
         new Symbol(50, 50, "二"),
     };
     var addressesToQuery = new List<uint>{0, 15, 50};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
 }
        public void ShouldCoverZeroLenghtSymbol()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(50, 50, "二"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(50, 100, "一"),
                new Symbol(50, 75, "三"),
            };
            var expectedSymbols = new List <Symbol>
            {
                new Symbol(50, 100, "一"),
                new Symbol(50, 75, "三"),
            };
            var addressesToQuery = new List <uint> {
                90, 55
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
            IReadOnlyCollection <Symbol> symbols;

            Assert.IsFalse(lookup.TryGetSymbolsByName("二", out symbols), "Symbol \"二\"should not be present.");
        }
        public void ShouldSplitCake()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 5, "一"),
                new Symbol(1, 4, "四"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(2, 2, "猫"),
            };
            var expectedSymbols = new List <Symbol> {
                new Symbol(0, 2, "一"),
                new Symbol(1, 2, "四"),
                new Symbol(2, 2, "猫"),
                new Symbol(2, 4, "四"),
                new Symbol(2, 5, "一"),
            };
            var addressesToQuery = new List <uint> {
                0, 1, 2, 3, 4
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
        public void ShouldHaveSlicedSymbolInNameLookup()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(20, 40, "国"),
                new Symbol(30, 40, "中"),
                new Symbol(50, 60, "五"),
                new Symbol(50, 55, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(30, 35, "中"),
            };
            var expectedSymbols = new List <Symbol> {
                new Symbol(20, 30, "国"),
                new Symbol(30, 35, "中"),
                new Symbol(35, 40, "中"),
                new Symbol(50, 60, "五"),
                new Symbol(50, 55, "三"),
            };
            var addressesToQuery = new List <uint> {
                20, 30, 35, 58, 50
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
            var name = expectedSymbols[1].Name;

            Assert.AreEqual(expectedSymbols[1], lookup.GetSymbolsByName(name).ElementAt(0));
            Assert.AreEqual(expectedSymbols[2], lookup.GetSymbolsByName(name).ElementAt(1));
        }
Ejemplo n.º 40
0
 public void ShouldFindOneSymbolBoundary()
 {
     var lookup = new SymbolLookup();
     lookup.InsertSymbol("Test", 0x100, 0x10);
     Assert.AreEqual("Test", lookup.GetSymbolByAddress(0x100).Name);
 }
        public void ShouldCutIntoCake()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(1, 85, "四"),
                new Symbol(2, 70, "国"),
                new Symbol(3, 60, "中"),
                new Symbol(20, 50, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(35, 40, "猫"),
            };
            var expectedSymbols = new List <Symbol> {
                new Symbol(0, 35, "一"),
                new Symbol(1, 35, "四"),
                new Symbol(2, 35, "国"),
                new Symbol(3, 35, "中"),
                new Symbol(20, 35, "三"),
                new Symbol(35, 40, "猫"),
                new Symbol(40, 100, "一"),
                new Symbol(40, 85, "四"),
                new Symbol(40, 70, "国"),
                new Symbol(40, 60, "中"),
                new Symbol(40, 50, "三"),
            };
            var addressesToQuery = new List <uint> {
                0, 1, 2, 10, 25, 37, 90, 80, 65, 55, 45
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
Ejemplo n.º 42
0
 public void ShouldFindTenSymbols()
 {
     var symbols = Enumerable.Range(1, 10).Select(x => MakeSymbolEntry(x.ToString(), (uint)(x * 10), 5)).ToList();
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols);
     foreach (var symbol in symbols)
     {
         Assert.AreEqual(symbol.Name, lookup.GetSymbolByAddress(symbol.Start + 2).Name);
     }
 }
Ejemplo n.º 43
0
 public void ShouldTrimAndOverShadowOnABase()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 100, "一"),
         new Symbol(1, 8, "四"),
         new Symbol(20, 40, "国"),
         new Symbol(30, 40, "中"),
         new Symbol(40, 60, "五"),
         new Symbol(45, 55, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(5, 50, "猫"),
         new Symbol(10, 15, "糞"),
     };
     var expectedSymbols = new List<Symbol> {
         new Symbol(0, 5, "一"),
         new Symbol(1, 5, "四"),
         new Symbol(5, 50, "猫"),
         new Symbol(10, 15, "糞"),
         new Symbol(50, 100, "一"),
         new Symbol(50, 60, "五"),
         new Symbol(50, 55, "三"),
     };
     var addressesToQuery = new List<uint>{0, 3, 5, 14, 60, 59, 51};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));        
 }
Ejemplo n.º 44
0
 public void ShouldFindDoubleCut()
 {
     var symbols = new List<Symbol>
     {
         MakeSymbolEntry("Big", 0, 100),
         MakeSymbolEntry("Alice", 10, 20),
         MakeSymbolEntry("Bob", 70, 20)
     };
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols);
     Assert.AreEqual("Big", lookup.GetSymbolByAddress(5).Name);
     Assert.AreEqual("Alice", lookup.GetSymbolByAddress(15).Name);
     Assert.AreEqual("Big", lookup.GetSymbolByAddress(35).Name);
     Assert.AreEqual("Bob", lookup.GetSymbolByAddress(75).Name);
     Assert.AreEqual("Big", lookup.GetSymbolByAddress(95).Name);
 }
Ejemplo n.º 45
0
        public void ShouldCorrectlyGuessZeroLengthSymbol()
        {
            var symbols = new List <Symbol>
            {
                MakeSymbolEntry("一", 20, 0),
                MakeSymbolEntry("三", 30, 10),
                MakeSymbolEntry("国", 40, 0),
                MakeSymbolEntry("五", 50, 50),
                MakeSymbolEntry("中", 60, 10),
                MakeSymbolEntry("猫", 65, 0),
                MakeSymbolEntry("私", 80, 0),
                MakeSymbolEntry("糞", 100, 0),
                MakeSymbolEntry("二", 110, 0)
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols);
            Symbol dummySymbol;

            Assert.IsFalse(lookup.TryGetSymbolByAddress(19, out dummySymbol));
            Assert.AreEqual("一", lookup.GetSymbolByAddress(20).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(21).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(40).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(41).Name);

            Assert.AreEqual("猫", lookup.GetSymbolByAddress(65).Name);
            Assert.AreEqual("中", lookup.GetSymbolByAddress(66).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(70).Name);

            Assert.AreEqual("私", lookup.GetSymbolByAddress(80).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(81).Name);

            Assert.AreEqual("糞", lookup.GetSymbolByAddress(100).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(101).Name);
            Assert.AreEqual("二", lookup.GetSymbolByAddress(110).Name);
            Assert.IsFalse(lookup.TryGetSymbolByAddress(111, out dummySymbol));
        }
        public void ShouldTrimAndOverShadowOnABase()
        {
            var symbols1 = new List <Symbol>
            {
                new Symbol(0, 100, "一"),
                new Symbol(1, 8, "四"),
                new Symbol(20, 40, "国"),
                new Symbol(30, 40, "中"),
                new Symbol(40, 60, "五"),
                new Symbol(45, 55, "三"),
            };
            var symbols2 = new List <Symbol>
            {
                new Symbol(5, 50, "猫"),
                new Symbol(10, 15, "糞"),
            };
            var expectedSymbols = new List <Symbol> {
                new Symbol(0, 5, "一"),
                new Symbol(1, 5, "四"),
                new Symbol(5, 50, "猫"),
                new Symbol(10, 15, "糞"),
                new Symbol(50, 100, "一"),
                new Symbol(50, 60, "五"),
                new Symbol(50, 55, "三"),
            };
            var addressesToQuery = new List <uint> {
                0, 3, 5, 14, 60, 59, 51
            };
            var lookup = new SymbolLookup();

            lookup.InsertSymbols(symbols1);
            lookup.InsertSymbols(symbols2);
            CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
        }
Ejemplo n.º 47
0
 public void ShouldCutIntoCake()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 100, "一"),
         new Symbol(1, 85, "四"),
         new Symbol(2, 70, "国"),
         new Symbol(3, 60, "中"),
         new Symbol(20, 50, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(35, 40, "猫"),
     };
     var expectedSymbols = new List<Symbol> {
         new Symbol(0, 35, "一"),
         new Symbol(1, 35, "四"),
         new Symbol(2, 35, "国"),
         new Symbol(3, 35, "中"),
         new Symbol(20, 35, "三"),
         new Symbol(35, 40, "猫"),
         new Symbol(40, 100, "一"),
         new Symbol(40, 85, "四"),
         new Symbol(40, 70, "国"),
         new Symbol(40, 60, "中"),
         new Symbol(40, 50, "三"),
     };
     var addressesToQuery = new List<uint>{0, 1, 2, 10, 25, 37, 90, 80, 65, 55, 45};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
 }
Ejemplo n.º 48
0
        public void ShouldFindNotSoComplicatedTest()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("一", 0, 100),
                MakeSymbolEntry("国", 50, 20),
                MakeSymbolEntry("五", 55, 5),
                MakeSymbolEntry("中", 60, 10),
                MakeSymbolEntry("猫", 80, 15),
                MakeSymbolEntry("私", 85, 5),
                MakeSymbolEntry("ICantSpeekJapaneese", 56, 2),
                MakeSymbolEntry("KoreanNeither", 58, 2)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Assert.AreEqual("一", lookup.GetSymbolByAddress(1).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(52).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(55).Name);
            Assert.AreEqual("中", lookup.GetSymbolByAddress(64).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(72).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(84).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(94).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(95).Name);
            Assert.AreEqual("ICantSpeekJapaneese", lookup.GetSymbolByAddress(57).Name);
            Assert.AreEqual("KoreanNeither", lookup.GetSymbolByAddress(59).Name);
        }
Ejemplo n.º 49
0
 public void ShouldTrimCakeToTopSymbol()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 100, "一"),
         new Symbol(1, 85, "四"),
         new Symbol(2, 70, "国"),
         new Symbol(3, 60, "中"),
         new Symbol(4, 60, "五"),
         new Symbol(20, 50, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(0, 30, "猫"),
         new Symbol(40, 100, "糞"),
     };
     var expectedSymbols = new List<Symbol> {
         new Symbol(0, 30, "猫"),
         new Symbol(30, 40, "三"),
         new Symbol(40, 100, "糞"),
     };
     var addressesToQuery = new List<uint>{10, 37, 80};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));        
 }
Ejemplo n.º 50
0
        public void ShouldWorkWithStackedTest()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("一", 0, 50),
                MakeSymbolEntry("国", 50, 50),
                MakeSymbolEntry("五", 65, 35),
                MakeSymbolEntry("中", 70, 30),
                MakeSymbolEntry("猫", 80, 20),
                MakeSymbolEntry("私", 81, 9),
                MakeSymbolEntry("糞", 90, 10)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);

            Assert.AreEqual("一", lookup.GetSymbolByAddress(1).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(52).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(66).Name);
            Assert.AreEqual("中", lookup.GetSymbolByAddress(71).Name);
            Assert.AreEqual("猫", lookup.GetSymbolByAddress(80).Name);
            Assert.AreEqual("私", lookup.GetSymbolByAddress(82).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(94).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(99).Name);
            Symbol dummy;
            Assert.IsFalse(lookup.TryGetSymbolByAddress(100, out dummy));
        }
Ejemplo n.º 51
0
 public void ShouldSplitCakeAfterSecondTower()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 100, "一"),
         new Symbol(1, 8, "四"),
         new Symbol(20, 40, "国"),
         new Symbol(30, 40, "中"),
         new Symbol(50, 60, "五"),
         new Symbol(50, 55, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(42, 47, "猫"),
         new Symbol(43, 43, "糞"),
     };
     var expectedSymbols = new List<Symbol> {
         new Symbol(0, 42, "一"),
         new Symbol(1, 8, "四"),
         new Symbol(20, 40, "国"),
         new Symbol(30, 40, "中"),
         new Symbol(42, 47, "猫"),
         new Symbol(43, 43, "糞"),
         new Symbol(47, 100, "一"),
         new Symbol(50, 60, "五"),
         new Symbol(50, 55, "三"),
     };
     var addressesToQuery = new List<uint>{41, 5, 25, 35, 45, 43, 48, 58, 50};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));        
 }
Ejemplo n.º 52
0
 public void ShouldNotCrashOnInsertDoubledSymbol()
 {
     var symbols = new List<Symbol>
     {
         MakeSymbolEntry("一", 0, 100),
         MakeSymbolEntry("二", 0, 100),
         MakeSymbolEntry("三", 100, 15),
         MakeSymbolEntry("四", 100, 15),
         MakeSymbolEntry("国", 10, 15),
         MakeSymbolEntry("五", 10, 15),
     };
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols);
     Symbol dummySymbol;
     foreach(var symbol in symbols)
     {
         lookup.GetSymbolsByName(symbol.Name);
         lookup.GetSymbolByAddress(symbol.Start);
         lookup.TryGetSymbolByAddress(symbol.End, out dummySymbol);
     }
 }
Ejemplo n.º 53
0
 public void ShouldCoverZeroLenghtSymbol()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(50, 50, "二"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(50, 100, "一"),
         new Symbol(50, 75, "三"),
     };
     var expectedSymbols = new List<Symbol>
     {
         new Symbol(50, 100, "一"),
         new Symbol(50, 75, "三"),
     };
     var addressesToQuery = new List<uint>{90, 55};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(expectedSymbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
     IReadOnlyCollection<Symbol> symbols;
     Assert.IsFalse(lookup.TryGetSymbolsByName("二", out symbols), "Symbol \"二\"should not be present.");
 }
Ejemplo n.º 54
0
 public void ShouldFindZeroLenghtSymbol()
 {
     var symbols = new List<Symbol>
     {
         new Symbol(0, 75, "一"),
         new Symbol(50, 75, "三"),
         new Symbol(75, 75, "二"),
         new Symbol(75, 100, "一"),
         new Symbol(75, 99, "三"),
     };
     var addressesToQuery = new List<uint>{5, 60, 75, 99, 76};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols);
     CollectionAssert.AreEqual(symbols, addressesToQuery.Select(address => lookup.GetSymbolByAddress(address)));
 }
Ejemplo n.º 55
0
 public void ShouldSortedIntervalsHaveExpectedLayout()
 {
     var symbols1 = new List<Symbol>
     {
         new Symbol(0, 100, "一"),
         new Symbol(1, 85, "四"),
         new Symbol(2, 70, "国"),
         new Symbol(80, 85, "猫"),
         new Symbol(3, 60, "中"),
         new Symbol(70, 75, "私"),
         new Symbol(4, 15, "五"),
         new Symbol(20, 35, "三"),
     };
     var symbols2 = new List<Symbol>
     {
         new Symbol(5, 25, "糞"),
         new Symbol(40, 82, "二"),
         new Symbol(50, 55, "ICantSpeekJapaneese"),
         new Symbol(45, 50, "ICantSpeekKorean"),
     };
     var expectedSymbols = new List<Symbol>
     {
         new Symbol(0, 5, "一"),
         new Symbol(1, 5, "四"),
         new Symbol(2, 5, "国"),
         new Symbol(3, 5, "中"),
         new Symbol(4, 5, "五"),
         new Symbol(5, 25, "糞"),
         new Symbol(25, 40, "中"),
         new Symbol(25, 35, "三"),
         new Symbol(40, 82, "二"),
         new Symbol(45, 50, "ICantSpeekKorean"),
         new Symbol(50, 55, "ICantSpeekJapaneese"),
         new Symbol(82, 100, "一"),
         new Symbol(82, 85, "猫"),
     };
     var addressesToQuery = new List<uint>{0, 1, 2, 3, 4, 10, 37, 30, 42, 47, 53, 90, 83};
     var lookup = new SymbolLookup();
     lookup.InsertSymbols(symbols1);
     lookup.InsertSymbols(symbols2);
     CollectionAssert.AreEqual(
         expectedSymbols, 
         addressesToQuery.Select(address => lookup.GetSymbolByAddress(address))
     );
 }
Ejemplo n.º 56
0
        public void ShouldCorrectlyGuessZeroLengthSymbol()
        {
            var symbols = new List<Symbol>
            {
                MakeSymbolEntry("一", 20, 0),
                MakeSymbolEntry("三", 30, 10),
                MakeSymbolEntry("国", 40, 0),
                MakeSymbolEntry("五", 50, 50),
                MakeSymbolEntry("中", 60, 10),
                MakeSymbolEntry("猫", 65, 0),
                MakeSymbolEntry("私", 80, 0),
                MakeSymbolEntry("糞", 100, 0),
                MakeSymbolEntry("二", 110, 0)
            };
            var lookup = new SymbolLookup();
            lookup.InsertSymbols(symbols);
            Symbol dummySymbol;
            Assert.IsFalse(lookup.TryGetSymbolByAddress(19, out dummySymbol));
            Assert.AreEqual("一", lookup.GetSymbolByAddress(20).Name);
            Assert.AreEqual("一", lookup.GetSymbolByAddress(21).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(40).Name);
            Assert.AreEqual("国", lookup.GetSymbolByAddress(41).Name);

            Assert.AreEqual("猫", lookup.GetSymbolByAddress(65).Name);
            Assert.AreEqual("中", lookup.GetSymbolByAddress(66).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(70).Name);

            Assert.AreEqual("私", lookup.GetSymbolByAddress(80).Name);
            Assert.AreEqual("五", lookup.GetSymbolByAddress(81).Name);

            Assert.AreEqual("糞", lookup.GetSymbolByAddress(100).Name);
            Assert.AreEqual("糞", lookup.GetSymbolByAddress(101).Name);
            Assert.AreEqual("二", lookup.GetSymbolByAddress(110).Name);
            Assert.IsFalse(lookup.TryGetSymbolByAddress(111, out dummySymbol));
        }