static void RunTest(Bin[] bins, int binIndex, Vector3Int binGridDimensions, byte expectedResultsRightLeft, byte expectedResultsUpDown, byte expectedResultsForeBack) { RefreshConnectivityInBin(bins, binIndex, binGridDimensions); UnitTester.Assert( "RefreshConnectivityInBin, Right + Left", bins[binIndex].voxelNeighborsRightLeft == expectedResultsRightLeft, true, new UnitTester.Parameter("Bins", bins), new UnitTester.Parameter("Index", binIndex), new UnitTester.Parameter("Dimensions", binGridDimensions) ); UnitTester.Assert( "RefreshConnectivityInBin, Up + Down", bins[binIndex].voxelNeighborsUpDown == expectedResultsUpDown, true, new UnitTester.Parameter("Bins", bins), new UnitTester.Parameter("Index", binIndex), new UnitTester.Parameter("Dimensions", binGridDimensions) ); UnitTester.Assert( "RefreshConnectivityInBin, Fore + Back", bins[binIndex].voxelNeighborsForeBack == expectedResultsForeBack, true, new UnitTester.Parameter("Bins", bins), new UnitTester.Parameter("Index", binIndex), new UnitTester.Parameter("Dimensions", binGridDimensions) ); }
public static void Main() { var assembly = typeof(TestsApplication).Assembly; Console.WriteLine(assembly.FullName); var unitTester = new UnitTester(); foreach (var type in assembly.GetTypes()) { if (typeof(TestFixture).IsAssignableFrom(type)) { foreach (var currentMethod in type.GetMethods()) { if (currentMethod.GetCustomAttributes(typeof(TestAttribute), false).Any()) { var instance = (TestFixture)type.GetConstructors()[0].Invoke(new object[0]); unitTester.QueueTest(instance, currentMethod); } } } } unitTester.RunTests(); }
private static void TestGetBiggestVoxelClusterIndex() { int biggest = Random.Range(1000, 10000); List <VoxelCluster> list = new List <VoxelCluster>() { new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)), new VoxelCluster(Random.Range(0, biggest)) }; int biggestIndex = Random.Range(0, list.Count); list.Insert(biggestIndex, new VoxelCluster(biggest)); UnitTester.Assert <List <VoxelCluster>, int>( "GetBiggestVoxelClusterIndex()", GetBiggestVoxelClusterIndex, new UnitTester.Parameter("List", list), expectedResult: biggestIndex ); }
private static void TestGetVoxelExists() { for (int i = 0; i < 25; i++) { Vector3Int binGridDimensions = new Vector3Int(Random.Range(1, 10), Random.Range(1, 10), Random.Range(1, 10)); Bin[] bins = UnitTester.GetBinsForTesting(binGridDimensions); void RunTest(Vector3Int coords, bool expectedResult) { UnitTester.Assert <Vector3Int, Bin[], Vector3Int, bool>( "GetVoxelExists", GetVoxelExists, new UnitTester.Parameter("Coords", coords), new UnitTester.Parameter("Bins", bins), new UnitTester.Parameter("Dimensions", binGridDimensions), expectedResult ); } for (int binIndex = 0; binIndex < bins.Length; binIndex++) { for (int localVoxelIndex = 0; localVoxelIndex < Bin.SIZE; localVoxelIndex++) { Vector3Int globalVoxelCoords = Bin.GetVoxelGlobalCoords(binIndex, localVoxelIndex, binGridDimensions); RunTest(globalVoxelCoords, true); Bin.SetBinVoxelExists(bins, binIndex, localVoxelIndex, exists: false); RunTest(globalVoxelCoords, false); } } RunTest(-Vector3Int.one, false); RunTest(CalculateVoxelGridDimensions(binGridDimensions), false); } }
public void Test_Create_Thread10_100W() { UnitTester.TestConcurrency(() => { Create(1000000); }, 10); Output.WriteLine("数量:" + _set.Count); }
static void RunTest(byte b, int index, bool expectedResult) { UnitTester.Assert <byte, int, bool>( "GetValueFromByte", GetValueFromByte, new UnitTester.Parameter("Byte", b), new UnitTester.Parameter("Index", index), expectedResult ); }
private static void TestCoordsToIndexAndViceVersa() { for (int i = 0; i < 25; i++) { Vector3Int dimensions = new Vector3Int(Random.Range(1, 10), Random.Range(1, 10), Random.Range(1, 10)); void TestCoordsToIndex(Vector3Int coords, int expectedResult) { UnitTester.Assert <Vector3Int, Vector3Int, int>( "CoordsToIndex()", CoordsToIndex, new UnitTester.Parameter("Coords", coords), new UnitTester.Parameter("Dimensions", dimensions), expectedResult ); } void TestIndexToCoords(int index, Vector3Int expectedResult) { UnitTester.Assert <int, Vector3Int, Vector3Int>( "IndexToCoords()", IndexToCoords, new UnitTester.Parameter("Index", index), new UnitTester.Parameter("Dimensions", dimensions), expectedResult ); } int actualIndex = 0; Vector3Int actualCoords = new Vector3Int(0, 0, 0); for (int z = 0; z < dimensions.z; z++) { for (int y = 0; y < dimensions.y; y++) { for (int x = 0; x < dimensions.x; x++) { actualCoords = new Vector3Int(x, y, z); TestCoordsToIndex(actualCoords, actualIndex); TestIndexToCoords(actualIndex, actualCoords); actualIndex++; } } } TestCoordsToIndex(dimensions, -1); TestCoordsToIndex(new Vector3Int(0, 0, -1), -1); TestIndexToCoords(-1, -Vector3Int.one); TestIndexToCoords(dimensions.x * dimensions.y * dimensions.z, -Vector3Int.one); } }
static void Main(string[] args) { Unit unit; int testID; UnitTester tester = new UnitTester(); // ID 1 testID = 1; unit = new Unit(testID); printResult(tester.setGetCommonProperty(unit, "infantry"), testID); // ID 2 testID = 2; unit = new Unit(testID); printResult(tester.setGetUnitSpecificProperty(unit, "hit points", 25), testID); // ID 3 testID = 3; unit = new Unit(testID); string property = "hit points"; unit.setProperties(property, 25); printResult(tester.changeExistingPropertyValue(unit, property, 15), testID); // ID 4 testID = 4; unit = new Unit(testID); printResult(tester.getNonExistentProperty(unit, "strength"), testID); // ID 5: Add an existing item testID = 5; unit = new Unit(testID); printResult(tester.addExistingProperty(unit, property, 15), testID); // ID 6 testID = 6; unit = new Unit(testID); printResult(tester.getIDProperty(unit, testID), testID); // ID 7 testID = 7; unit = new Unit(testID); printResult(tester.setGetNameProperty(unit, "Chuck"), testID); // ID 8 testID = 8; unit = new Unit(testID); Weapon weapon = new Weapon(); printResult(tester.addGetWeapons(unit, weapon), testID); Console.ReadKey(); }
public void FunktionsnetzExport() { try { UnitTester.RunUnitExportTests(typeof(FunktionsnetzNetwork), Subfolder); } catch (Exception ex) { Console.WriteLine(ex); Assert.Fail(ex.Message); } }
public void ZielmodellTests() { try { UnitTester.RunUnitVerificationTests(typeof(ZielmodellNetwork), Subfolder); } catch (Exception ex) { Console.WriteLine(ex); Assert.Fail(ex.Message); } }
private static void TestCalculateVoxelGridDimensions() { for (int i = 0; i < 25; i++) { Vector3Int binGridDimensions = new Vector3Int(Random.Range(1, 10), Random.Range(1, 10), Random.Range(1, 10)); UnitTester.Assert <Vector3Int, Vector3Int>( "CalculateVoxelGridDimensions()", CalculateVoxelGridDimensions, new UnitTester.Parameter("BinGridDimensions", binGridDimensions), expectedResult: binGridDimensions * Bin.WIDTH ); } }
private static void TestGetPivot() { Vector3Int dimensions = new Vector3Int(8, 8, 8); Bin[] cluster = new Bin[dimensions.x * dimensions.y * dimensions.z]; int binIndex = 0; for (int z = 0; z < dimensions.z; z++) { for (int y = 0; y < dimensions.y; y++) { for (int x = 0; x < dimensions.x; x++) { bool exists = x == 0 || y == 0 || z == 0 || x == dimensions.x - 1 || y == dimensions.y - 1 || z == dimensions.z - 1; cluster[binIndex] = new Bin(binIndex, dimensions); Bin.SetBinAllVoxelsExists(cluster, binIndex, exists: exists); binIndex++; } } } UnitTester.Assert <Bin[], Vector3Int, bool, Vector3>( "GetPivot", GetPivot, new UnitTester.Parameter("Cluster", cluster), new UnitTester.Parameter("Dimensions", dimensions), new UnitTester.Parameter("IsStatic", false), expectedResult: new Vector3((dimensions.x * Bin.WIDTH - 1) / 2f, (dimensions.y * Bin.WIDTH - 1) / 2f, (dimensions.z * Bin.WIDTH - 1) / 2f) ); UnitTester.Assert <Bin[], Vector3Int, bool, Vector3>( "GetPivot", GetPivot, new UnitTester.Parameter("Cluster", cluster), new UnitTester.Parameter("Dimensions", dimensions), new UnitTester.Parameter("IsStatic", true), expectedResult: new Vector3((dimensions.x * Bin.WIDTH - 1) / 2f, -0.5f, (dimensions.z * Bin.WIDTH - 1) / 2f) ); }
private static void TestAreCoordsWithinDimensions() { for (int i = 0; i < 25; i++) { Vector3Int dimensions = new Vector3Int(Random.Range(1, 10), Random.Range(1, 10), Random.Range(1, 10)); Vector3Int coords = new Vector3Int(Random.Range(0, dimensions.x), Random.Range(0, dimensions.y), Random.Range(0, dimensions.z)); UnitTester.Assert <Vector3Int, Vector3Int, bool>( "AreCoordsWithinDimensions()", AreCoordsWithinDimensions, new UnitTester.Parameter("Coords", coords), new UnitTester.Parameter("Dimensions", dimensions), expectedResult: true ); UnitTester.Assert <Vector3Int, Vector3Int, bool>( "AreCoordsWithinDimensions()", AreCoordsWithinDimensions, new UnitTester.Parameter("Coords", dimensions), new UnitTester.Parameter("Dimensions", dimensions), expectedResult: false ); } }
private void runTests_Click(object sender, EventArgs e) { UnitTester tester = new UnitTester(); tester.RunTests(); }
private static void TestTryFindCluster() { Vector3Int binGridDimensions = new Vector3Int(3, 3, 3); int binCount = binGridDimensions.x * binGridDimensions.y * binGridDimensions.z; Bin[] bins; bool[] visitedBins; VoxelCluster cluster0, cluster1; // ================ Test solid block ================ bins = new Bin[binCount]; visitedBins = new bool[binCount]; for (int i = 0; i < binCount; i++) { AddBin(VoxelGrid.IndexToCoords(i, binGridDimensions)); } RefreshBinGridConnectivity(bins, binGridDimensions); cluster0 = TryFindCluster(0, bins, binGridDimensions, visitedBins); UnitTester.Assert( "Testing Solid Block, Cluster Bin Count", cluster0.Bins.Length == binCount, expectedResult: true, new UnitTester.Parameter("Cluster Bin Count", cluster0.Bins.Length), new UnitTester.Parameter("Expected Bin Count", binCount) ); UnitTester.Assert( "Testing Solid Block, Cluster Dimensions", cluster0.Dimensions == binGridDimensions, expectedResult: true, new UnitTester.Parameter("Cluster Dimensions", cluster0.Dimensions), new UnitTester.Parameter("Expected Dimensions", binGridDimensions) ); UnitTester.Assert( "Testing Solid Block, Cluster Offset", cluster0.VoxelOffset == Vector3Int.zero, expectedResult: true, new UnitTester.Parameter("Cluster Offset", cluster0.VoxelOffset), new UnitTester.Parameter("Expected Offset", Vector3Int.zero) ); // ================ Test arch-shape ================ bins = new Bin[binCount]; visitedBins = new bool[binCount]; AddBin(new Vector3Int(0, 0, 0)); AddBin(new Vector3Int(0, 0, 1)); AddBin(new Vector3Int(0, 0, 2)); AddBin(new Vector3Int(0, 1, 0)); AddBin(new Vector3Int(0, 1, 1)); AddBin(new Vector3Int(0, 1, 2)); AddBin(new Vector3Int(0, 2, 0)); AddBin(new Vector3Int(0, 2, 1)); AddBin(new Vector3Int(0, 2, 2)); AddBin(new Vector3Int(1, 2, 0)); AddBin(new Vector3Int(1, 2, 1)); AddBin(new Vector3Int(1, 2, 2)); AddBin(new Vector3Int(2, 0, 0)); AddBin(new Vector3Int(2, 0, 1)); AddBin(new Vector3Int(2, 0, 2)); AddBin(new Vector3Int(2, 1, 0)); AddBin(new Vector3Int(2, 1, 1)); AddBin(new Vector3Int(2, 1, 2)); AddBin(new Vector3Int(2, 2, 0)); AddBin(new Vector3Int(2, 2, 1)); AddBin(new Vector3Int(2, 2, 2)); RefreshBinGridConnectivity(bins, binGridDimensions); cluster0 = TryFindCluster(0, bins, binGridDimensions, visitedBins); UnitTester.Assert( "Testing Arch Block, Cluster Bin Count", cluster0.Bins.Length == cluster0.Dimensions.x * cluster0.Dimensions.y * cluster0.Dimensions.z, expectedResult: true, new UnitTester.Parameter("Cluster Bin Count", cluster0.Bins.Length), new UnitTester.Parameter("Expected Bin Count", cluster0.Dimensions.x * cluster0.Dimensions.y * cluster0.Dimensions.z) ); UnitTester.Assert( "Testing Arch Block, Cluster Dimensions", cluster0.Dimensions == binGridDimensions, expectedResult: true, new UnitTester.Parameter("Cluster Dimensions", cluster0.Dimensions), new UnitTester.Parameter("Expected Dimensions", binGridDimensions) ); UnitTester.Assert( "Testing Arch Block, Cluster Offset", cluster0.VoxelOffset == Vector3Int.zero, expectedResult: true, new UnitTester.Parameter("Cluster Offset", cluster0.VoxelOffset), new UnitTester.Parameter("Expected Offset", Vector3Int.zero) ); // ================ Test two clusters touching diagonally ================ bins = new Bin[binCount]; visitedBins = new bool[binCount]; AddBin(new Vector3Int(0, 0, 0)); AddBin(new Vector3Int(0, 0, 1)); AddBin(new Vector3Int(0, 0, 2)); AddBin(new Vector3Int(1, 1, 0)); AddBin(new Vector3Int(1, 1, 1)); AddBin(new Vector3Int(1, 1, 2)); AddBin(new Vector3Int(2, 0, 0)); AddBin(new Vector3Int(2, 0, 1)); AddBin(new Vector3Int(2, 0, 2)); AddBin(new Vector3Int(2, 1, 0)); AddBin(new Vector3Int(2, 1, 1)); AddBin(new Vector3Int(2, 1, 2)); AddBin(new Vector3Int(2, 2, 0)); AddBin(new Vector3Int(2, 2, 1)); AddBin(new Vector3Int(2, 2, 2)); RefreshBinGridConnectivity(bins, binGridDimensions); cluster0 = TryFindCluster(VoxelGrid.CoordsToIndex(new Vector3Int(0, 0, 0), binGridDimensions), bins, binGridDimensions, visitedBins); cluster1 = TryFindCluster(VoxelGrid.CoordsToIndex(new Vector3Int(1, 1, 0), binGridDimensions), bins, binGridDimensions, visitedBins); //for(int i = 0; i < cluster1.Bins.Length; i++) { // if(cluster1.Bins[i] == null) { // continue; // } // Debug.Log(cluster1.Bins[i].Index + ", " + cluster1.Bins[i].Coords); //} UnitTester.Assert( "Testing Two Clusters Touching Diagonally, Cluster #1 Bin Count", cluster0.Bins.Length == cluster0.Dimensions.x * cluster0.Dimensions.y * cluster0.Dimensions.z, expectedResult: true, new UnitTester.Parameter("Bin Count", cluster0.Bins.Length), new UnitTester.Parameter("Expected Count", cluster0.Dimensions.x * cluster0.Dimensions.y * cluster0.Dimensions.z) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally, Cluster #2 Bin Count", cluster1.Bins.Length == cluster1.Dimensions.x * cluster1.Dimensions.y * cluster1.Dimensions.z, expectedResult: true, new UnitTester.Parameter("Bin Count", cluster1.Bins.Length), new UnitTester.Parameter("Expected Count", cluster1.Dimensions.x * cluster1.Dimensions.y * cluster1.Dimensions.z) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally, Cluster #1 Dimensions", cluster0.Dimensions == new Vector3Int(1, 1, 3), expectedResult: true, new UnitTester.Parameter("Dimensions", cluster0.Dimensions), new UnitTester.Parameter("Expected Dimensions", new Vector3Int(1, 1, 3)) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally, Cluster #2 Dimensions", cluster1.Dimensions == new Vector3Int(2, 3, 3), expectedResult: true, new UnitTester.Parameter("Dimensions", cluster1.Dimensions), new UnitTester.Parameter("Expected Dimensions", new Vector3Int(2, 3, 3)) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally, Cluster #1 Offset", cluster0.VoxelOffset == Vector3Int.zero, expectedResult: true, new UnitTester.Parameter("Offset", cluster0.VoxelOffset), new UnitTester.Parameter("Expected Offset", Vector3Int.zero) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally, Cluster #2 Offset", cluster1.VoxelOffset == new Vector3Int(1, 0, 0) * Bin.WIDTH, expectedResult: true, new UnitTester.Parameter("Offset", cluster1.VoxelOffset), new UnitTester.Parameter("Expected Offset", new Vector3Int(1, 0, 0) * Bin.WIDTH) ); // ================ Test two clusters touching... diagonally diagonally ================ bins = new Bin[binCount]; visitedBins = new bool[binCount]; AddBin(new Vector3Int(0, 0, 2)); AddBin(new Vector3Int(1, 1, 1)); AddBin(new Vector3Int(2, 0, 0)); AddBin(new Vector3Int(2, 0, 1)); AddBin(new Vector3Int(2, 0, 2)); AddBin(new Vector3Int(2, 1, 0)); AddBin(new Vector3Int(2, 1, 1)); AddBin(new Vector3Int(2, 1, 2)); AddBin(new Vector3Int(2, 2, 0)); AddBin(new Vector3Int(2, 2, 1)); AddBin(new Vector3Int(2, 2, 2)); RefreshBinGridConnectivity(bins, binGridDimensions); cluster0 = TryFindCluster(VoxelGrid.CoordsToIndex(new Vector3Int(0, 0, 2), binGridDimensions), bins, binGridDimensions, visitedBins); cluster1 = TryFindCluster(VoxelGrid.CoordsToIndex(new Vector3Int(1, 1, 1), binGridDimensions), bins, binGridDimensions, visitedBins); UnitTester.Assert( "Testing Two Clusters Touching Diagonally Diagonally, Cluster #1 Bin Count", cluster0.Bins.Length == cluster0.Dimensions.x * cluster0.Dimensions.y * cluster0.Dimensions.z, expectedResult: true, new UnitTester.Parameter("Bin Count", cluster0.Bins.Length), new UnitTester.Parameter("Expected Count", cluster0.Dimensions.x * cluster0.Dimensions.y * cluster0.Dimensions.z) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally Diagonally, Cluster #2 Bin Count", cluster1.Bins.Length == cluster1.Dimensions.x * cluster1.Dimensions.y * cluster1.Dimensions.z, expectedResult: true, new UnitTester.Parameter("Bin Count", cluster1.Bins.Length), new UnitTester.Parameter("Expected Count", cluster1.Dimensions.x * cluster1.Dimensions.y * cluster1.Dimensions.z) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally Diagonally, Cluster #1 Dimensions", cluster0.Dimensions == new Vector3Int(1, 1, 1), expectedResult: true, new UnitTester.Parameter("Dimensions", cluster0.Dimensions), new UnitTester.Parameter("Expected Dimensions", new Vector3Int(1, 1, 1)) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally Diagonally, Cluster #2 Dimensions", cluster1.Dimensions == new Vector3Int(2, 3, 3), expectedResult: true, new UnitTester.Parameter("Dimensions", cluster1.Dimensions), new UnitTester.Parameter("Expected Dimensions", new Vector3Int(2, 3, 3)) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally Diagonally, Cluster #1 Offset", cluster0.VoxelOffset == new Vector3Int(0, 0, 2) * Bin.WIDTH, expectedResult: true, new UnitTester.Parameter("Offset", cluster0.VoxelOffset), new UnitTester.Parameter("Expected Offset", new Vector3Int(0, 0, 2) * Bin.WIDTH) ); UnitTester.Assert( "Testing Two Clusters Touching Diagonally Diagonally, Cluster #2 Offset", cluster1.VoxelOffset == new Vector3Int(1, 0, 0) * Bin.WIDTH, expectedResult: true, new UnitTester.Parameter("Offset", cluster1.VoxelOffset), new UnitTester.Parameter("Expected Offset", new Vector3Int(1, 0, 0) * Bin.WIDTH) ); void AddBin(Vector3Int newBinCoords) { int binIndex = VoxelGrid.CoordsToIndex(newBinCoords, binGridDimensions); bins[binIndex] = new Bin(binIndex, binGridDimensions); Bin.SetBinAllVoxelsExists(bins, binIndex, exists: true); }
protected override void Render() { var tester = new UnitTester(); tester.Test(GetValue<string>("test_dll"), _testsPerformed, _testsTotal); }
override protected void Render() { var tester = new UnitTester(); tester.Test(GetValue <string>("test_dll"), _testsPerformed, _testsTotal); }