Example #1
0
 public void TestCannotGetEmptyStringKey()
 {
     TST<int> tst = new TST<int>();
     tst.Put("bla", 1);
     Assert.IsTrue(tst.Contains("bla"));
     tst.Get("");
 }
Example #2
0
    static void Main(string [] args)
    {
        string [] strarr = { "shiva",     "sairaj",   "ranju",    "gokul", "ganesh",     "ram",    "rajkumar", "tamil", "anisha",   "anjana"
                             ,            "nantha",   "nitheesh", "ravi",  "saraswathy", "balaji", "vinoth",   "prem",  "sudarson", "sathya","prakash", "mano",
                             "jagadeesh", "santhosh", "jude",     "sruthi" };
        var       tst = new TST();

        foreach (var str in strarr)
        {
            tst.Insert(str);
        }
        tst.Display();
        int i = 0;

        foreach (var str in strarr)
        {
            if (i == strarr.Length * 3 / 4)
            {
                break;
            }
            i++;
            tst.Delete(str);
        }
        tst.Display();
    }
Example #3
0
        void test_Mtch_3()
        {
            Log.set(" test_Mtch_3: Rule 5 и Group < C235, Pl30 >");
            rule = new Rule.Rule(5);
            ElmAttSet.ElmAttSet elm = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D74-3134-353338303236",
                "C235", "Steel", "Pl30", 0, 0, 0, 1001);
            Dictionary <string, ElmAttSet.ElmAttSet> els
                = new Dictionary <string, ElmAttSet.ElmAttSet>();

            els.Add(elm.guid, elm);
            List <string> guids = new List <string>(); guids.Add(elm.guid);
            var           model = new Model.Model();

            model.setElements(els);
            model.getGroups();
            var gr = model.elmGroups[0];

            TST.Eq(gr.guids.Count, 1);
            TST.Eq(gr.mat, "c235");
            TST.Eq(gr.prf, "pl30");
            var doc  = Docs.getDoc("Полоса СтальхолдингM");
            var csDP = new Dictionary <SType, string>();

//31/3            csFPs = rule.Parser(FP.type.CompSet, doc.LoadDescription);
// 2/4            Comp comp1 = new Comp(doc, 2, csDP);
// 2/4            Comp comp2 = new Comp(doc, 12, csDP);
// 2/4            List<Comp> comps = new List<Comp> { comp1, comp2 };
// 2/4            CS cs = new CS("test_CS", null, rule, doc.LoadDescription, comps);
// 2/4            TST.Eq(cs.csDP.Count, 4);

            //////////////////////////TST.Eq(comp1.isMatch(gr, rule), false);
            //////////////////////////TST.Eq(comp2.isMatch(gr, rule), true);
            Log.exit();
        }
Example #4
0
        void test_Mtch_2()
        {
            Log.set(" test_Mtch_2: Rule 15 и Group < B12,5 , 1900x1600 > ");
            rule = new Rule.Rule(15);
            ElmAttSet.ElmAttSet elB = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D7B-3134-353338303236",
                "B12,5", "Concrete", "1900x1600", 0, 0, 0, 1000);
            Dictionary <string, ElmAttSet.ElmAttSet> els = new Dictionary <string, ElmAttSet.ElmAttSet>();

            els.Add(elB.guid, elB);
            List <string> guids = new List <string>(); guids.Add(elB.guid);
            var           model = new Model.Model();

            model.setElements(els);
            model.getGroups();
            var gr = model.elmGroups[0];

            TST.Eq(gr.guids.Count, 1);
            var match = new Mtch(gr, rule);

            TST.Eq(match.ok == OK.Match, true);
            var cmp = match.component;

//31/3            TST.Eq(cmp.fps[SType.Material].pars[0].par.ToString(), "b12,5");
            Log.exit();
        }
Example #5
0
        public void TestTST()
        {
            // build symbol table
            TST<string> st = new TST<string>();
            string[] a = new string[] { "by", "sea", "sells", "she", "shells", "shore", "the", };
            for (int i = 0; i < a.Length; i++) st.Put(a[i], i.ToString());

            // print results
            if (st.Size() < 100)
            {
                Debug.WriteLine("keys(\"\"):");
                foreach (string key in st.Keys())
                    Debug.WriteLine(key + " " + st.Get(key));
                Debug.WriteLine(Environment.NewLine);
            }

            Debug.WriteLine("longestPrefixOf(\"shellsort\"):");
            Debug.WriteLine(st.LongestPrefixOf("shellsort"));
            Debug.WriteLine(Environment.NewLine);

            Debug.WriteLine("longestPrefixOf(\"quicksort\"):");
            Debug.WriteLine(st.LongestPrefixOf("quicksort"));
            Debug.WriteLine(Environment.NewLine);

            Debug.WriteLine("keysWithPrefix(\"shor\"):");
            foreach (string s in st.KeysWithPrefix("shor"))
                Debug.WriteLine(s);
            Debug.WriteLine(Environment.NewLine);

            Debug.WriteLine("keysThatMatch(\".he.l.\"):");
            foreach (string s in st.KeysThatMatch(".he.l."))
                Debug.WriteLine(s);
        }
Example #6
0
    public static void compress()
    {
        string text = BinaryStdIn.readString();
        TST    tST  = new TST();
        int    i;

        for (i = 0; i < 256; i++)
        {
            tST.put(new StringBuilder().append("").append((char)i).toString(), Integer.valueOf(i));
        }
        i = 257;
        while (java.lang.String.instancehelper_length(text) > 0)
        {
            string text2 = tST.longestPrefixOf(text);
            BinaryStdOut.write(((Integer)tST.get(text2)).intValue(), 12);
            int num = java.lang.String.instancehelper_length(text2);
            if (num < java.lang.String.instancehelper_length(text) && i < 4096)
            {
                TST    arg_A5_0 = tST;
                string arg_A5_1 = java.lang.String.instancehelper_substring(text, 0, num + 1);
                int    arg_A0_0 = i;
                i++;
                arg_A5_0.put(arg_A5_1, Integer.valueOf(arg_A0_0));
            }
            text = java.lang.String.instancehelper_substring(text, num);
        }
        BinaryStdOut.write(256, 12);
        BinaryStdOut.close();
    }
Example #7
0
        public string getBaggageAllowance(int segmentNum)
        {
            Response baggageData   = new Response();
            string   strDataReturn = "";
            PNR      objPNR        = new PNR();

            string strDataReturnTemp = "";

            TST objTST = new TST();

            objTST.RetrieveCurrentTst(objSession);

            int segmentCount = 1;

            try
            {
                foreach (k1aTST.AirSegment _baggageAllowance in objTST.AirSegments)
                {
                    strDataReturnTemp = _baggageAllowance.BaggageAllowance;

                    if (segmentCount == segmentNum)
                    {
                        strDataReturn = strDataReturnTemp;
                    }

                    segmentCount += 1;
                }
            }
            catch (Exception ex)
            {
                _errorStr = ex.Message;
            }

            return(strDataReturn);
        }
        public void CheckIsZeroSetsZ()
        {
            // TST <ea>
            // 0100 1010 1011 1001  0x4AB9
            // 0000 0000 1111 1111  0x00FF
            // 0000 0000 0000 0000  0x0000
            // TST 0x00FF0000

            byte[] data = new byte[]
            {
                0x4A, 0xB9, 0x00, 0xFF, 0x00, 0x00
            };

            MegadriveState state = new MegadriveState(new Data(data), 0x00000000, 0x00000000, 0x000000, 0x3FFFFF, 0x0FF0000, 0xFFFFFF);

            state.WriteByte(0xFF0000, 0x00);
            state.FetchOpCode();

            state.SR |= 0x0011;

            var opcode = new TST(state);

            Assert.That(opcode.Assembly, Is.EqualTo("TST.l $00FF0000"));

            Assert.That(opcode.Size, Is.EqualTo(Size.Long));

            Assert.That(state.PC, Is.EqualTo(0x00000006));

            Assert.That(state.Condition_X, Is.True);    // not affected
            Assert.That(state.Condition_N, Is.False);
            Assert.That(state.Condition_Z, Is.True);
            Assert.That(state.Condition_V, Is.False);   // always cleared
            Assert.That(state.Condition_C, Is.False);   // always cleared
        }
Example #9
0
 public void TestCannotGetNullKey()
 {
     TST<int> tst = new TST<int>();
     tst.Put("bla", 1);
     Assert.IsTrue(tst.Contains("bla"));
     tst.Get(null);
 }
        public static TST Test0(string message)
        {
            Core.print(message);
            var t = new TST();

            t.x = 10;
            t.y = 15;
            return(t);
        }
Example #11
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - shellsST.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            var fieName = string.Empty;
            switch (fileNumber)
            {
                case "1":
                    fieName = "shellsST.txt";
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();
            var st = new TST<Integer>();
            for (var i = 0; i< content.Length; i++)
            {
                st.Put(content[i], i);
            }

            // print results
            if (st.Size() < 100)
            {
                Console.WriteLine("keys(\"\"):");
                foreach (var key in st.Keys())
                {
                    Console.WriteLine($"{key} {st.Get(key).Value}");
                }
                Console.WriteLine();
            }

            Console.WriteLine("longestPrefixOf(\"shellsort\"):");
            Console.WriteLine(st.LongestPrefixOf("shellsort"));
            Console.WriteLine();

            Console.WriteLine("longestPrefixOf(\"shell\"):");
            Console.WriteLine(st.LongestPrefixOf("shell"));
            Console.WriteLine();

            Console.WriteLine("keysWithPrefix(\"shor\"):");
            foreach (var s in st.KeysWithPrefix("shor"))
                Console.WriteLine(s);
            Console.WriteLine();

            Console.WriteLine("keysThatMatch(\".he.l.\"):");
            foreach (var s in st.KeysThatMatch(".he.l."))
                Console.WriteLine(s);

            Console.ReadLine();
        }
    private void subscribeTo(TST.TimeSeriesTreeDropdownWithMult c_, bool do_=true)
    {
      c_.DeleteClicked -= handleTreeControlClose;
      c_.SizeChanged -= handleControlResize;

      if (!do_) return;

      c_.DeleteClicked += handleTreeControlClose;
      c_.SizeChanged += handleControlResize;
    }
Example #13
0
    public static void Main(string[] args)
    {
        TST tt = new TST();

        tt.insert("banana");
        tt.insert("apple");
        tt.insert("mango");
        Console.WriteLine("\nSearch results for apple, banana, grapes and mango :");
        tt.find("apple");
        tt.find("banana");
        tt.find("mango");
        tt.find("grapes");
    }
Example #14
0
        public void TestCanGetAllKeysWithAGivenPrefix()
        {
            TST<int> tst = new TST<int>();
            string[] keys = testKeystwo.Split(' ');
            for (int i = 0; i < keys.Length; i++)
            {
                tst.Put(keys[i], i);
            }

            Assert.IsTrue(tst.PrefixMatch("se").Count() == 3);
            foreach (var key in tst.PrefixMatch("se"))
            {
                Assert.IsTrue(key.StartsWith("se"));
            }
        }
Example #15
0
        public void TestAllKeys()
        {
            TST<int> tst = new TST<int>();
            string[] keys = testKeys.Split(' ');
            for (int i = 0; i < keys.Length; i++)
            {
                tst.Put(keys[i], i);
            }

            Assert.IsTrue(keys.Length == tst.Keys().Count());
            foreach (var key in tst.Keys())
            {
               Assert.IsTrue( keys.Contains(key));
            }
        }
Example #16
0
        //////////////        private void test_getSectionText()
        //////////////        {
        //////////////            Log.set("test_getSectionTest(Section.Material, text");
        //28/5/////////////// 7/3/2017 /////////////////            TST.Eq(getSectionText(FP.Section.Material, "Профиль: L 20 x 5; M: C245; Price: 2690"), "c245");
        //////////////            Log.exit();
        //////////////        }

        //////////////private void test_isSectionMatch()
        //////////////{
        //////////////    Log.set("isSectionMatch(Section.Material, C245, rule.text)");

        //////////////    /////// 7/3/2017 ////            bool ok = isSectionMatch(FP.Section.Material, "C245", "Профиль: L * x * ст*; длина: * = * м; M: ст *;");

        //////////////    Log.exit();
        //////////////}

        private void test_Mtch_1()
        {
            Log.set(" test_Mtch_1: Rule 4 и Group<C255, L20x4>");
            Rule.Rule           rule = new Rule.Rule(4);
            ElmAttSet.ElmAttSet el   = new ElmAttSet.ElmAttSet(
                "ID56A7442F-0000-0D70-3134-353338303236",
                "C245", "Steel", "Уголок20X4", 0, 0, 0, 1000);
            Dictionary <string, ElmAttSet.ElmAttSet> els = new Dictionary <string, ElmAttSet.ElmAttSet>();

            els.Add(el.guid, el);
            List <string> guids = new List <string>(); guids.Add(el.guid);

            ElmAttSet.Group gr    = new ElmAttSet.Group(els, "C245", "Уголок20X4", guids);
            Mtch            match = new Mtch(gr, rule);

            TST.Eq(match.ok == OK.Match, true);
            Log.exit();
        }
Example #17
0
    void TSTStart()
    {
        string[] strs = txt.text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        // build symbol table from standard input
        TST <int> st = new TST <int>();

        for (int i = 0; i < strs.Length; i++)
        {
            string key = strs[i];
            st.Put(key, i);
        }

        // print results
        if (st.size() < 100)
        {
            print("keys(\"\"):");
            foreach (string key in st.keys())
            {
                print(key + " " + st.Get(key));
            }
        }

        print("longestPrefixOf(\"shellsort\"):");
        print(st.longestPrefixOf("shellsort"));


        print("longestPrefixOf(\"shell\"):");
        print(st.longestPrefixOf("shell"));


        print("keysWithPrefix(\"shor\"):");
        foreach (string s in st.keysWithPrefix("shor"))
        {
            print(s);
        }


        print("keysThatMatch(\".he.l.\"):");
        foreach (string s in st.keysThatMatch(".he.l."))
        {
            print(s);
        }
    }
Example #18
0
File: LZW.cs Project: PajLe/paa-lab
        public LZW(string inputFileName, string outputFileName)
        {
            _fileToDecode = outputFileName;

            using (BinaryReader br = new BinaryReader(File.Open(inputFileName, FileMode.Open)))
            {
                using (BinaryWriter bw = new BinaryWriter(File.Open(outputFileName, FileMode.Create)))
                {
                    TST <uint>    st         = new TST <uint>();
                    StringBuilder inputChars = new StringBuilder();
                    //br.BaseStream.Position = 0;
                    while (br.BaseStream.Position != br.BaseStream.Length)
                    {
                        inputChars.Append(Convert.ToChar(br.ReadByte()));
                    }
                    string input = inputChars.ToString();
                    _inputLength = input.Length;

                    for (uint i = 0; i < R; i++)
                    {
                        st.put("" + (char)i, i);
                    }
                    uint code = R + 1;  // R is codeword for EOF

                    int inputStartIndex = 0;
                    while (_inputLength > inputStartIndex)
                    {
                        string s = st.longestPrefixOf(input, inputStartIndex); // Find max prefix match s.

                        bw.WriteIntBits(st.get(s), W);                         // Print s's code.
                        int t = s.Length;
                        if (t < _inputLength - inputStartIndex && code < L)
                        {
                            st.put(input.Substring(inputStartIndex, t + 1), code++); // Add s to symbol table.
                        }
                        inputStartIndex += t;                                        // instead of the slow substring operation
                    }

                    bw.WriteIntBits(R, W);
                }
            }
        }
Example #19
0
        void TrieSTTest()
        {
            var strArr = FileHandler.ReadFileAsStrArr("shellsST.txt");

            strArr.Show();
            //var st = new TrieST<int>();
            var st = new TST <int>();

            for (int i = 1; i < strArr.Length; i++)
            {
                //st.Put(strArr[i], i);
                st.Put(strArr[i], i);
            }
            //st.Put("bad", 100);
            Console.WriteLine(st.Get("she"));
            Console.WriteLine(st.Get("sells"));
            Console.WriteLine(st.Get("shore"));
            Console.WriteLine(st.Get("shore1"));
            Console.WriteLine(st.Get("zoo"));
            Console.ReadKey();
        }
Example #20
0
    // private bool DeleteHelper(ref Node root, int i, string str) {
    //  if (root == null)
    //      return false;
    //  if (i > str.Length)
    //      return false;
    //  if (i == str.Length && root.IsEnd) {
    //      root.IsEnd = false;
    //      if (!ContainsChildren(root))
    //          root = null; return true;
    //  }
    //  else if (DeleteHelper(ref root.child[(int)str[i]], i + 1, str)) {
    //      if (!ContainsChildren(root))
    //          root = null;
    //      return true;
    //  }
    //  return true;
    // }
    // public void Delete(string str) {
    //  DeleteHelper(ref head, 0, str);
    // }
    static void Main()
    {
        string [] strarr = { "shiva",     "sairaj",   "ranju",    "gokul", "ganesh",     "ram",    "rajkumar", "tamil", "anisha",   "anjana"
                             ,            "nantha",   "nitheesh", "ravi",  "saraswathy", "balaji", "vinoth",   "prem",  "sudarson", "sathya","prakash", "mano",
                             "jagadeesh", "santhosh", "jude",     "sruthi" };
        var       trie = new TST();

        foreach (var str in strarr)
        {
            trie.Insert(str);
        }
        trie.Display();
        Console.WriteLine();
        // foreach (var v in strarr)
        //  Console.Write(trie.Search(v) + " ");
        // foreach (var str in strarr)
        // {
        //  trie.Delete(str);
        //  Console.WriteLine();
        //  trie.Display();
        // }

        // trie.Print();
    }
Example #21
0
        public void Compress()
        {
            string    input = BinaryStdIn.ReadString();
            TST <int> st    = new TST <int>();

            for (int i = 0; i < R; i++)
            {
                st.Put("" + i, i);
            }
            int code = R + 1; //标记结束

            while (input.Length > 0)
            {
                string s = st.LongestPrefixOf(input); //匹配最长前缀
                BinaryStdOut.Write(st.Get(s), W);
                int t = s.Length;
                if (t < input.Length && code < L) //将s加入符号表
                {
                    st.Put(input.Substring(0, t + 1), code++);
                }
                input = input.Substring(t);
            }
            BinaryStdOut.Write(R, W);
        }
Example #22
0
 public void TestPrefixMatchThrowsNullException()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeystwo.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     tst.PrefixMatch(null);
 }
Example #23
0
 public void TestWildCard()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeystwo.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     Assert.IsTrue(tst.WildcardMatch("..e").Count() == 3);
     foreach (var key in tst.WildcardMatch("..e"))
     {
         Assert.IsTrue(key.EndsWith("e"));
     }
 }
Example #24
0
 public SpellChecker()
 {
     tst = new TST <int>();
 }
Example #25
0
 public void TestWildCardReturnsEmptyCollection()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeystwo.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     Assert.IsTrue(tst.WildcardMatch(null).Count() == 0);
     Assert.IsTrue(tst.WildcardMatch("").Count() == 0);
 }
Example #26
0
        public void Run()
        {
            Console.WriteLine("Choose file:");     // Prompt
            Console.WriteLine("1 - shellsST.txt"); // Prompt
            Console.WriteLine("or quit");          // Prompt

            var fileNumber = Console.ReadLine();
            var fieName    = string.Empty;

            switch (fileNumber)
            {
            case "1":
                fieName = "shellsST.txt";
                break;

            case "quit":
                return;

            default:
                return;
            }


            var @in     = new In($"Files\\Strings\\{fieName}");
            var content = @in.ReadAllStrings();
            var st      = new TST <Integer>();

            for (var i = 0; i < content.Length; i++)
            {
                st.Put(content[i], i);
            }

            // print results
            if (st.Size() < 100)
            {
                Console.WriteLine("keys(\"\"):");
                foreach (var key in st.Keys())
                {
                    Console.WriteLine($"{key} {st.Get(key).Value}");
                }
                Console.WriteLine();
            }

            Console.WriteLine("longestPrefixOf(\"shellsort\"):");
            Console.WriteLine(st.LongestPrefixOf("shellsort"));
            Console.WriteLine();

            Console.WriteLine("longestPrefixOf(\"shell\"):");
            Console.WriteLine(st.LongestPrefixOf("shell"));
            Console.WriteLine();

            Console.WriteLine("keysWithPrefix(\"shor\"):");
            foreach (var s in st.KeysWithPrefix("shor"))
            {
                Console.WriteLine(s);
            }
            Console.WriteLine();

            Console.WriteLine("keysThatMatch(\".he.l.\"):");
            foreach (var s in st.KeysThatMatch(".he.l."))
            {
                Console.WriteLine(s);
            }


            Console.ReadLine();
        }
Example #27
0
 public void TestCannnotCreateTreeWithWrongRadix()
 {
     TST<int> tst = new TST<int>(128);
     Assert.IsNotNull(tst);
 }
Example #28
0
        static void Main(string[] args)
        {
            // TESTING search tree Insertion
            // 2643 adds
            Console.WriteLine(" Ternary Search Tree Add ");
            Stopwatch myStopWatch = new Stopwatch();
            myData    data        = new myData();
            TST <int> myTry       = new TST <int>();

            myStopWatch.Start();
            for (int i = 0; i < 3; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("3 Insertions: " + myStopWatch.Elapsed);

            // 1000 adds

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 9; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("9 Insertions: " + myStopWatch.Elapsed);
            // 100 adds

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 27; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("27 Insertions: " + myStopWatch.Elapsed);

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 81; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("81 Insertions: " + myStopWatch.Elapsed);
            // 100 adds

            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 243; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("243 Insertions: " + myStopWatch.Elapsed);
            // 10 adds
            myStopWatch = new Stopwatch();
            data        = new myData();
            myTry       = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 729; i++)
            {
                myTry.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("729 Insertions: " + myStopWatch.Elapsed);
            // Testing Dictionary search tree Insertions
            // 977 adds
            Console.WriteLine(" Testing the Dictionary");
            myStopWatch = new Stopwatch();
            data        = new myData();
            Dictionary <string, int> myDictionary = new Dictionary <string, int>();

            myStopWatch.Start();
            for (int i = 0; i < 3; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("3 Insertions: " + myStopWatch.Elapsed);


            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 27; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("27 Insertions: " + myStopWatch.Elapsed);

            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 81; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("81 Insertions: " + myStopWatch.Elapsed);

            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 243; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("243 Insertions: " + myStopWatch.Elapsed);

            myStopWatch  = new Stopwatch();
            data         = new myData();
            myDictionary = new Dictionary <string, int>();
            myStopWatch.Start();
            for (int i = 0; i < 729; i++)
            {
                myDictionary.Add(data.words[i], i);
            }
            myStopWatch.Stop();
            Console.WriteLine("729 Insertions: " + myStopWatch.Elapsed);

            // TESTING // Contains// Partial Match // Autocomplete

            Console.WriteLine(" Ternary Search Tree Add ");

            data  = new myData();
            myTry = new TST <int>();
            myStopWatch.Start();
            for (int i = 0; i < 1000; i++)
            {
                myTry.Add(data.words[i], i);
            }

            Boolean       value = myTry.Contains("chaos");
            List <string> list  = myTry.Autocomplete("ch");
            List <string> list2 = myTry.PartialMatch("ch***");
            List <string> list3 = myTry.PartialMatch("***b**");

            Console.WriteLine("List: AutoComplete ch ");
            foreach (string element in list)
            {
                Console.Write(element + " ");
            }
            Console.WriteLine();
            Console.WriteLine("List2: PartialMatch ch*** ");
            foreach (string element in list2)
            {
                Console.Write(element + " ");
            }
            Console.WriteLine();
            Console.WriteLine("List3: PartialMatch ***b** ");
            foreach (string element in list3)
            {
                Console.Write(element + " ");
            }


            Console.ReadLine();
        }
Example #29
0
 public void TestCannotPutNull()
 {
     TST<int> tst = new TST<int>();
     tst.Put("bla", 1);
     Assert.IsTrue(tst.Contains("bla"));
     tst.Put(null, 0);
 }
Example #30
0
        public void TestCreateTree()
        {
            TST<int> tst = new TST<int>();
               Assert.IsNotNull(tst);

               TST<int> tst2 = new TST<int>(65536);
               Assert.IsNotNull(tst2);
        }
Example #31
0
 public void TestKeyHasToHaveValue()
 {
     TST<int> tst = new TST<int>();
     tst.Put("seashells", 1);
     Assert.IsTrue(tst.Contains("seashells"));
     // "sea" is only a prefix of the key
     tst.Get("sea");
 }
Example #32
0
        public void TestLoadKeys()
        {
            TST<int> tst = new TST<int>();
            string[] keys = testKeys.Split(' ');
            for (int i = 0; i < keys.Length; i++)
            {
                tst.Put(keys[i], i);
            }

            Assert.IsTrue(tst.Size() == keys.Length);
        }
Example #33
0
 public void TestLongestPrefix()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeystwo.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     Assert.IsTrue(tst.LongestPrefixOf("shellsort").Equals("shells"));
     Assert.IsFalse(tst.LongestPrefixOf("shellsort").Equals("she"));
 }
Example #34
0
 public void TestReadKeys()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeys.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     for (int i = 0; i < keys.Length; i++)
     {
         Assert.IsTrue(tst.Contains(keys[i]));
         Assert.IsTrue(tst.Get(keys[i]) == i);
     }
 }
Example #35
0
 public void TestLongestPrefixReturnsNullIfNullArgument()
 {
     TST<int> tst = new TST<int>();
     string[] keys = testKeystwo.Split(' ');
     for (int i = 0; i < keys.Length; i++)
     {
         tst.Put(keys[i], i);
     }
     Assert.IsNull(tst.LongestPrefixOf(null));
 }