public void IsSelectedTest() { setBuildings.SetValue(1, 0); Assert.IsFalse(setBuildings.IsSelected(0)); Assert.IsTrue(setBuildings.IsSelected(1)); Assert.IsFalse(setBuildings.IsSelected(2)); setBuildings.SetValue(1, -1); }
public void IsSelectedTest() { setBuildings.SetValue(1, 0); Assert.That(setBuildings.IsSelected(0), Is.False); Assert.That(setBuildings.IsSelected(1), Is.True); Assert.That(setBuildings.IsSelected(2), Is.False); setBuildings.SetValue(1, -1); }
public void SimulateCostBaseTest() { setBuildings.SetValue(0, -1); setBuildings.SetValue(1, 0); setBuildings.SetValue(2, 8); #if DEBUG setBuildings.Print(); #endif var varSimCost = new Dictionary <int, double[]>(); for (int i = 0; i < setBuildings.Domain(1).MaxValue() + 1; ++i) { varSimCost[i] = new double[setBuildings.GetNumberVariables()]; for (var j = 0; j < setBuildings.GetNumberVariables(); ++j) { varSimCost[i][j] = -1; } } var noHoles = new WallShape(setBuildings); var vecCosts = noHoles.SimulateCost(1, varSimCost); foreach (var tuple in vecCosts) { if (tuple.Key == 0 || tuple.Key == 7 || tuple.Key == 8 || tuple.Key == 12 || tuple.Key == 13) { Assert.AreEqual(2.0, tuple.Value); } else if (tuple.Key == 1 || tuple.Key == 6 || tuple.Key == 11 || tuple.Key == 16 || tuple.Key == 17 || tuple.Key == 18) { Assert.AreEqual(0.0, tuple.Value); } else { Assert.AreEqual(4.0, tuple.Value); } } }
public void MatrixIndexTests() { var set = new SetVariables( list, 5, 10, new SetVariables.Point( 4, 5 ), new SetVariables.Point( 0, 0 ) ); set.SetValue( 1, 14 ); for( int i = 0 ; i < 5 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) if( ( i == 1 && j == 4 ) || ( i == 1 && j == 5 ) || ( i == 1 && j == 6 ) || ( i == 2 && j == 4 ) || ( i == 2 && j == 5 ) || ( i == 2 && j == 6 ) ) { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.EqualTo( 1 ) ); Assert.That( l[ 0 ], Is.EqualTo( 1 ) ); } else { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.Zero ); } set.ShiftValue( 1 ); for( int i = 0 ; i < 5 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) if( ( i == 1 && j == 7 ) || ( i == 1 && j == 5 ) || ( i == 1 && j == 6 ) || ( i == 2 && j == 7 ) || ( i == 2 && j == 5 ) || ( i == 2 && j == 6 ) ) { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.EqualTo( 1 ) ); Assert.That( l[ 0 ], Is.EqualTo( 1 ) ); } else { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.Zero ); } set.UnshiftValue( 1 ); for( int i = 0 ; i < 5 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) if( ( i == 1 && j == 4 ) || ( i == 1 && j == 5 ) || ( i == 1 && j == 6 ) || ( i == 2 && j == 4 ) || ( i == 2 && j == 5 ) || ( i == 2 && j == 6 ) ) { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.EqualTo( 1 ) ); Assert.That( l[ 0 ], Is.EqualTo( 1 ) ); } else { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.Zero ); } set.SetValue( 1, 27 ); for( int i = 0 ; i < 5 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) if( ( i == 3 && j == 7 ) || ( i == 3 && j == 8 ) || ( i == 3 && j == 9 ) || ( i == 2 && j == 7 ) || ( i == 2 && j == 8 ) || ( i == 2 && j == 9 ) ) { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.EqualTo( 1 ) ); Assert.That( l[ 0 ], Is.EqualTo( 1 )); } else { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.Zero ); } set.ShiftValue( 1 ); for( int i = 0 ; i < 5 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) if( ( i == 3 && j == 0 ) || ( i == 3 && j == 1 ) || ( i == 3 && j == 2 ) || ( i == 4 && j == 0 ) || ( i == 4 && j == 1 ) || ( i == 4 && j == 2 ) ) { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.EqualTo( 1 ) ); Assert.That( l[ 0 ], Is.EqualTo( 1 ) ); } else { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.Zero ); } set.UnshiftValue( 1 ); for( int i = 0 ; i < 5 ; ++i ) for( int j = 0 ; j < 10 ; ++j ) if( ( i == 3 && j == 7 ) || ( i == 3 && j == 8 ) || ( i == 3 && j == 9 ) || ( i == 2 && j == 7 ) || ( i == 2 && j == 8 ) || ( i == 2 && j == 9 ) ) { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.EqualTo( 1 ) ); Assert.That( l[ 0 ], Is.EqualTo( 1 ) ); } else { var l = set.BuildingsAt( i, j ); Assert.That( l.Count, Is.Zero ); } set.ShiftValue( 1 ); set.SetValue( 2, 22 ); set.SetValue( 3, 37 ); int overlaps; int unbuild; set.Shift( 2, out overlaps, out unbuild ); Assert.That( overlaps, Is.EqualTo( -2 ) ); Assert.That( unbuild, Is.Zero ); Assert.That( set.GetBuildingsAround( 2 ).Contains( 1 ), Is.True ); Assert.That( set.GetBuildingsAround( 2 ).Contains( 3 ), Is.True ); Assert.That( set.GetBuildingsAround( 1 ).Contains( 2 ), Is.True ); Assert.That( set.GetBuildingsAround( 3 ).Contains( 2 ), Is.True ); Assert.That( set.GetBuildingsAround( 2 ).Count, Is.EqualTo( 2 ) ); Assert.That( set.GetBuildingsAround( 3 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsAround( 1 ).Count, Is.EqualTo( 1 ) ); set.Shift( 2, out overlaps, out unbuild ); Assert.That( overlaps, Is.EqualTo( 2 ) ); Assert.That( unbuild, Is.Zero ); var listSmallBuildings = new List<Variable> { new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ), new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ), new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ), new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ), new Variable( "X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0 ) }; set = new SetVariables( listSmallBuildings, 5, 10, new SetVariables.Point( 4, 5 ), new SetVariables.Point( 0, 0 ) ); set.SetValue( 0, 25 ); set.SetValue( 1, 26 ); set.SetValue( 2, 35 ); set.SetValue( 3, 24 ); set.SetValue( 4, 15 ); Assert.That( set.GetBuildingsOnRight( 0 ).Contains( 1 ), Is.True ); Assert.That( set.GetBuildingsBelow( 0 ).Contains( 2 ), Is.True ); Assert.That( set.GetBuildingsOnLeft( 0 ).Contains( 3 ), Is.True ); Assert.That( set.GetBuildingsAbove( 0 ).Contains( 4 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 0 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsBelow( 0 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsOnLeft( 0 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsAbove( 0 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.CountAround( 0 ), Is.EqualTo( 4 ) ); Assert.That( set.GetBuildingsOnLeft( 1 ).Contains( 0 ), Is.True ); Assert.That( set.GetBuildingsOnLeft( 1 ).Contains( 2 ), Is.True ); Assert.That( set.GetBuildingsOnLeft( 1 ).Contains( 4 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 1 ).Count, Is.Zero ); Assert.That( set.GetBuildingsBelow( 1 ).Count, Is.Zero ); Assert.That( set.GetBuildingsOnLeft( 1 ).Count, Is.EqualTo( 3 ) ); Assert.That( set.GetBuildingsAbove( 1 ).Count, Is.Zero ); Assert.That( set.CountAround( 1 ), Is.EqualTo( 3 ) ); Assert.That( set.GetBuildingsOnRight( 2 ).Contains( 1 ), Is.True ); Assert.That( set.GetBuildingsOnLeft( 2 ).Contains( 3 ), Is.True ); Assert.That( set.GetBuildingsAbove( 2 ).Contains( 0 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 2 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsBelow( 2 ).Count, Is.Zero ); Assert.That( set.GetBuildingsOnLeft( 2 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsAbove( 2 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.CountAround( 2 ), Is.EqualTo( 3 ) ); Assert.That( set.GetBuildingsOnRight( 3 ).Contains( 0 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 3 ).Contains( 2 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 3 ).Contains( 4 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 3 ).Count, Is.EqualTo( 3 ) ); Assert.That( set.GetBuildingsBelow( 3 ).Count, Is.Zero ); Assert.That( set.GetBuildingsOnLeft( 3 ).Count, Is.Zero ); Assert.That( set.GetBuildingsAbove( 3 ).Count, Is.Zero ); Assert.That( set.CountAround( 3 ), Is.EqualTo( 3 ) ); Assert.That( set.GetBuildingsOnRight( 4 ).Contains( 1 ), Is.True ); Assert.That( set.GetBuildingsBelow( 4 ).Contains( 0 ), Is.True ); Assert.That( set.GetBuildingsOnLeft( 4 ).Contains( 3 ), Is.True ); Assert.That( set.GetBuildingsOnRight( 4 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsBelow( 4 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsOnLeft( 4 ).Count, Is.EqualTo( 1 ) ); Assert.That( set.GetBuildingsAbove( 4 ).Count, Is.Zero ); Assert.That( set.CountAround( 4 ), Is.EqualTo( 3 ) ); Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.False ); set.SetValue( 0, 0 ); Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.True ); set.SetValue( 0, 1 ); Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.False ); set.SetValue( 0, 45 ); Assert.That( set.IsOnStartingOrTargetTile( 0 ), Is.True ); }
public void MatrixIndexTests() { var set = new SetVariables(list, 5, 10, new SetVariables.Point(4, 5), new SetVariables.Point(0, 0)); set.SetValue(1, 14); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 10; ++j) { if ((i == 1 && j == 4) || (i == 1 && j == 5) || (i == 1 && j == 6) || (i == 2 && j == 4) || (i == 2 && j == 5) || (i == 2 && j == 6)) { var l = set.BuildingsAt(i, j); Assert.AreEqual(1, l.Count); Assert.AreEqual(1, l[0]); } else { var l = set.BuildingsAt(i, j); Assert.AreEqual(0, l.Count); } } } set.ShiftValue(1); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 10; ++j) { if ((i == 1 && j == 7) || (i == 1 && j == 5) || (i == 1 && j == 6) || (i == 2 && j == 7) || (i == 2 && j == 5) || (i == 2 && j == 6)) { var l = set.BuildingsAt(i, j); Assert.AreEqual(1, l.Count); Assert.AreEqual(1, l[0]); } else { var l = set.BuildingsAt(i, j); Assert.AreEqual(0, l.Count); } } } set.UnshiftValue(1); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 10; ++j) { if ((i == 1 && j == 4) || (i == 1 && j == 5) || (i == 1 && j == 6) || (i == 2 && j == 4) || (i == 2 && j == 5) || (i == 2 && j == 6)) { var l = set.BuildingsAt(i, j); Assert.AreEqual(1, l.Count); Assert.AreEqual(1, l[0]); } else { var l = set.BuildingsAt(i, j); Assert.AreEqual(0, l.Count); } } } set.SetValue(1, 27); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 10; ++j) { if ((i == 3 && j == 7) || (i == 3 && j == 8) || (i == 3 && j == 9) || (i == 2 && j == 7) || (i == 2 && j == 8) || (i == 2 && j == 9)) { var l = set.BuildingsAt(i, j); Assert.AreEqual(1, l.Count); Assert.AreEqual(1, l[0]); } else { var l = set.BuildingsAt(i, j); Assert.AreEqual(0, l.Count); } } } set.ShiftValue(1); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 10; ++j) { if ((i == 3 && j == 0) || (i == 3 && j == 1) || (i == 3 && j == 2) || (i == 4 && j == 0) || (i == 4 && j == 1) || (i == 4 && j == 2)) { var l = set.BuildingsAt(i, j); Assert.AreEqual(1, l.Count); Assert.AreEqual(1, l[0]); } else { var l = set.BuildingsAt(i, j); Assert.AreEqual(0, l.Count); } } } set.UnshiftValue(1); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 10; ++j) { if ((i == 3 && j == 7) || (i == 3 && j == 8) || (i == 3 && j == 9) || (i == 2 && j == 7) || (i == 2 && j == 8) || (i == 2 && j == 9)) { var l = set.BuildingsAt(i, j); Assert.AreEqual(1, l.Count); Assert.AreEqual(1, l[0]); } else { var l = set.BuildingsAt(i, j); Assert.AreEqual(0, l.Count); } } } set.ShiftValue(1); set.SetValue(2, 22); set.SetValue(3, 37); int overlaps; int unbuild; set.Shift(2, out overlaps, out unbuild); Assert.AreEqual(-2, overlaps); Assert.AreEqual(0, unbuild); Assert.IsTrue(set.GetBuildingsAround(2).Contains(1)); Assert.IsTrue(set.GetBuildingsAround(2).Contains(3)); Assert.IsTrue(set.GetBuildingsAround(1).Contains(2)); Assert.IsTrue(set.GetBuildingsAround(3).Contains(2)); Assert.AreEqual(2, set.GetBuildingsAround(2).Count); Assert.AreEqual(1, set.GetBuildingsAround(3).Count); Assert.AreEqual(1, set.GetBuildingsAround(1).Count); set.Shift(2, out overlaps, out unbuild); Assert.AreEqual(2, overlaps); Assert.AreEqual(0, unbuild); var listSmallBuildings = new List <Variable> { new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0), new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0), new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0), new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0), new Variable("X", "xxx", 1, 1, 0, 0, 0, 0, Race.Unknown, 0, 0) }; set = new SetVariables(listSmallBuildings, 5, 10, new SetVariables.Point(4, 5), new SetVariables.Point(0, 0)); set.SetValue(0, 25); set.SetValue(1, 26); set.SetValue(2, 35); set.SetValue(3, 24); set.SetValue(4, 15); Assert.IsTrue(set.GetBuildingsOnRight(0).Contains(1)); Assert.IsTrue(set.GetBuildingsBelow(0).Contains(2)); Assert.IsTrue(set.GetBuildingsOnLeft(0).Contains(3)); Assert.IsTrue(set.GetBuildingsAbove(0).Contains(4)); Assert.AreEqual(1, set.GetBuildingsOnRight(0).Count); Assert.AreEqual(1, set.GetBuildingsBelow(0).Count); Assert.AreEqual(1, set.GetBuildingsOnLeft(0).Count); Assert.AreEqual(1, set.GetBuildingsAbove(0).Count); Assert.AreEqual(4, set.CountAround(0)); Assert.IsTrue(set.GetBuildingsOnLeft(1).Contains(0)); Assert.IsTrue(set.GetBuildingsOnLeft(1).Contains(2)); Assert.IsTrue(set.GetBuildingsOnLeft(1).Contains(4)); Assert.AreEqual(0, set.GetBuildingsOnRight(1).Count); Assert.AreEqual(0, set.GetBuildingsBelow(1).Count); Assert.AreEqual(3, set.GetBuildingsOnLeft(1).Count); Assert.AreEqual(0, set.GetBuildingsAbove(1).Count); Assert.AreEqual(3, set.CountAround(1)); Assert.IsTrue(set.GetBuildingsOnRight(2).Contains(1)); Assert.IsTrue(set.GetBuildingsOnLeft(2).Contains(3)); Assert.IsTrue(set.GetBuildingsAbove(2).Contains(0)); Assert.AreEqual(1, set.GetBuildingsOnRight(2).Count); Assert.AreEqual(0, set.GetBuildingsBelow(2).Count); Assert.AreEqual(1, set.GetBuildingsOnLeft(2).Count); Assert.AreEqual(1, set.GetBuildingsAbove(2).Count); Assert.AreEqual(3, set.CountAround(2)); Assert.IsTrue(set.GetBuildingsOnRight(3).Contains(0)); Assert.IsTrue(set.GetBuildingsOnRight(3).Contains(2)); Assert.IsTrue(set.GetBuildingsOnRight(3).Contains(4)); Assert.AreEqual(3, set.GetBuildingsOnRight(3).Count); Assert.AreEqual(0, set.GetBuildingsBelow(3).Count); Assert.AreEqual(0, set.GetBuildingsOnLeft(3).Count); Assert.AreEqual(0, set.GetBuildingsAbove(3).Count); Assert.AreEqual(3, set.CountAround(3)); Assert.IsTrue(set.GetBuildingsOnRight(4).Contains(1)); Assert.IsTrue(set.GetBuildingsBelow(4).Contains(0)); Assert.IsTrue(set.GetBuildingsOnLeft(4).Contains(3)); Assert.AreEqual(1, set.GetBuildingsOnRight(4).Count); Assert.AreEqual(1, set.GetBuildingsBelow(4).Count); Assert.AreEqual(1, set.GetBuildingsOnLeft(4).Count); Assert.AreEqual(0, set.GetBuildingsAbove(4).Count); Assert.AreEqual(3, set.CountAround(4)); Assert.IsFalse(set.IsOnStartingOrTargetTile(0)); set.SetValue(0, 0); Assert.IsTrue(set.IsOnStartingOrTargetTile(0)); set.SetValue(0, 1); Assert.IsFalse(set.IsOnStartingOrTargetTile(0)); set.SetValue(0, 45); Assert.IsTrue(set.IsOnStartingOrTargetTile(0)); // set.SetValue( 0, 25 ); // Assert.IsFalse( set.IsNeighborOfSTTBuildings( 0 ) ); // set.SetValue( 0, 11 ); // Assert.IsTrue( set.IsNeighborOfSTTBuildings( 0 ) ); // set.SetValue( 0, 44 ); // Assert.IsTrue( set.IsNeighborOfSTTBuildings( 0 ) ); }