public static void WorldTestBlock(int tyles = 16, int treeChaining = 2) { MySqlConnection connection = new MySqlConnection("Database=cubeworld;DataSource=localhost;UserId=root;Password=root"); Models.TilesModel model = new Models.TilesModel(connection, tyles); Map.Map map = new Map.Map(model, tyles, treeChaining); Map.Rectangle coord = new Map.Rectangle(0, 0, 1), coords = new Map.Rectangle(0, 0, 1); Map.Block blockA, blockB; Trees.QuadTree.QuadTree<Map.Block> tree; int totalBlocks = (int)Math.Pow(tyles, treeChaining + 1) * (int)Math.Pow(tyles, treeChaining + 1); List<Map.Block> list, list2; int errors = 0, tests = 0; tree = map.getTree(new Map.Rectangle(0, 0, 16)); return; for (int i = 1; i < 15; i++) { list = map.getIntersect(new Map.Rectangle(8, 0, 16)); list2 = map.getIntersect(new Map.Rectangle(i, 0, 16)); foreach (Map.Block b in list) { foreach (Map.Block b2 in list2) { if (b.location.x == b2.location.x) { if (b.location.y == b2.location.y) { tests++; if (b.val != b2.val) { errors++; } } } } } //System.Threading.Thread.Sleep(1000); } Console.WriteLine("Hodnoceni počtu dlaždic: {0}% ({1} ok, {2} bad)", (100 * (tests - errors)) / tests, tests - errors, errors); }
public static void WorldTest(int tyles = 16, int treeChaining = 2) { Stopwatch sw = new Stopwatch(); sw.Start(); MySqlConnection connection = new MySqlConnection("Database=cubeworld;DataSource=localhost;UserId=root;Password=root"); Models.TilesModel model = new Models.TilesModel(connection, tyles); Map.Map map = new Map.Map(model, tyles, treeChaining); Map.Rectangle coord = new Map.Rectangle(0, 0, 1), coords = new Map.Rectangle(0, 0, 1); Map.Block blockA, blockB; Trees.QuadTree.QuadTree<Map.Block> tree; int totalBlocks = (int)Math.Pow(tyles, treeChaining + 1) * (int)Math.Pow(tyles, treeChaining + 1); /* for (int i = 0; i < 16; i++) { coord.x = tyles * i; block = map.getBlock(coord); Console.WriteLine("Block X: {0}, Y: {1}, Value: {2}.", block.location.x, block.location.y, block.val); } */ int test = 0, failsTiles = 0, failsValues = 0, valuesTest = 0; for (int i = 0; i < 2; i++) { for (int x = 0; x < (int)Math.Pow(tyles, treeChaining); x += tyles) { for (int y = 0; y < (int)Math.Pow(tyles, treeChaining); y += tyles) { test++; //Console.WriteLine("{0}. iteration, Tree {1}, {2}", tyles * x + y, x, y); coord.x = x; coord.y = y; tree = map.getTree(coord); Trees.QuadTree.QuadTree<Map.Block> dbtree = model.loadTree(new Map.Rectangle(coord.x, coord.y, tyles)); for (int ix = 0; ix < tyles; ix++) { for (int iy = 0; iy < tyles; iy++) { valuesTest++; coords.x = ix + coord.x * tyles; coords.y = iy + coord.y * tyles; //Console.WriteLine("Try find {0} {1} {2}", coords.x, coords.y, dbtree.DumpCount()); blockA = tree.Get(coords); blockB = dbtree.Get(coords); //Console.WriteLine("Found A:{0}, B:{1}", blockA != null, blockB != null); if (blockA != null && blockB != null) { if (blockA.val != blockB.val) { failsValues++; } } else if (blockA == null ^ blockB == null) { failsValues++; } //System.Threading.Thread.Sleep(1000); } } //Console.WriteLine("Test: {0} valid: {1}", tree.DumpCount(), tree.DumpCount() == tyles * tyles); if (tree.DumpCount() != tyles * tyles) { //Console.WriteLine("Test: {0} valid: {1}; x {2} y {3}", tree.DumpCount(), tree.DumpCount() == tyles * tyles, x, y); tree.Dump(); dbtree.Dump(); failsTiles += 1; //Console.ReadKey(); } Trees.QuadTree.QuadTree<Map.Block>.unsetAllTree(); } } } sw.Stop(); mt.WaitOne(); Console.WriteLine("Očekávaný počet mapových bloků {0}.", totalBlocks); Console.WriteLine("Hodnoceni počtu dlaždic: {0}% ({1} ok, {2} bad)", (100 * (test - failsTiles)) / test, test - failsTiles, failsTiles); Console.WriteLine("Hodnoceni hodnot bloků : {0}% ({1} ok, {2} bad)", (100 * (valuesTest - failsValues)) / valuesTest, valuesTest - failsValues, failsValues); Console.WriteLine("Celkem uloženo bloků {0}", Program.TotalInserted); Console.WriteLine("Test zabral {0} s", sw.ElapsedMilliseconds / 1000); mt.ReleaseMutex(); }