示例#1
0
        private void TestAddIndex()
        {
            try
            {
                _logger.Message("Testing AddIndex");
                //making the table
                String indexPath = GetFilePath.TableColumnIndex(dbName, tableName, "Int");

                List <Column> cols = new List <Column>();
                cols.Add(new Column(Column.DataType.Int, "Int", 100));
                cols.Add(new Column(Column.DataType.Double, "Double", 1));
                cols.Add(new Column(Column.DataType.Char, "String", 20));
                manager.CreateTable(dbName, tableName, cols);

                //making records to be inserted
                List <String> l1 = new List <string>();
                l1.Add("5");
                l1.Add("5.1");
                l1.Add("random1");
                Record r1 = new Record(l1);

                List <String> l2 = new List <string>();
                l2.Add("2048000");
                l2.Add("5.2");
                l2.Add("random2");
                Record r2 = new Record(l2);

                List <String> l3 = new List <string>();
                l3.Add("-409600");
                l3.Add("5.3");
                l3.Add("random3");
                Record r3 = new Record(l3);

                manager.InsertRecord(r1);
                manager.InsertRecord(r2);
                manager.InsertRecord(r3);

                manager.AddIndex(new Column(Column.DataType.Int, "Int", 100));

                Assert.IsTrue(File.Exists(indexPath));
                BtreeDictionary <Index <int>, int> btree = (BtreeDictionary <Index <int>, int>)Converter.FileToObject(indexPath);
                Assert.AreEqual(3, btree.Count);
                Assert.IsTrue(btree.ContainsKey(new Index <int>(2048000, 54)));
                Assert.IsTrue(btree.ContainsValue(96));
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
            }
            finally
            {
                manager.DropTable(dbName, tableName);
            }
        }