TerrainTest.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using NUnit.Framework;
  29. using OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes;
  30. namespace OpenSim.Region.Environment.Modules.World.Terrain.Tests
  31. {
  32. [TestFixture]
  33. public class TerrainTest
  34. {
  35. [Test]
  36. public void BrushTest()
  37. {
  38. bool[,] allowMask = new bool[256, 256];
  39. int x;
  40. int y;
  41. for (x=0; x<128; x++)
  42. {
  43. for (y=0; y<256; y++)
  44. {
  45. allowMask[x,y] = true;
  46. }
  47. }
  48. //
  49. // Test RaiseSphere
  50. //
  51. TerrainChannel map = new TerrainChannel(256, 256);
  52. ITerrainPaintableEffect effect = new RaiseSphere();
  53. effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 0.1);
  54. Assert.That(map[127, 128] > 0.0, "Raise brush should raising value at this point (127,128).");
  55. Assert.That(map[124, 128] > 0.0, "Raise brush should raising value at this point (124,128).");
  56. Assert.That(map[123, 128] == 0.0, "Raise brush should not change value at this point (123,128).");
  57. Assert.That(map[128, 128] == 0.0, "Raise brush should not change value at this point (128,128).");
  58. Assert.That(map[0, 128] == 0.0, "Raise brush should not change value at this point (0,128).");
  59. //
  60. // Test LowerSphere
  61. //
  62. map = new TerrainChannel(256, 256);
  63. for (x=0; x<map.Width; x++)
  64. {
  65. for (y=0; y<map.Height; y++)
  66. {
  67. map[x,y] = 1.0;
  68. }
  69. }
  70. effect = new LowerSphere();
  71. effect.PaintEffect(map, allowMask, 128.0, 128.0, -1.0, 2, 6.0);
  72. Assert.That(map[127, 128] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
  73. Assert.That(map[127, 128] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
  74. Assert.That(map[124, 128] < 1.0, "Lower brush should lowering value at this point (124,128).");
  75. Assert.That(map[123, 128] == 1.0, "Lower brush should not change value at this point (123,128).");
  76. Assert.That(map[128, 128] == 1.0, "Lower brush should not change value at this point (128,128).");
  77. Assert.That(map[0, 128] == 1.0, "Lower brush should not change value at this point (0,128).");
  78. }
  79. [Test]
  80. public void TerrainChannelTest()
  81. {
  82. TerrainChannel x = new TerrainChannel(256, 256);
  83. Assert.That(x[0, 0] == 0.0, "Terrain not initialising correctly.");
  84. x[0, 0] = 1.0;
  85. Assert.That(x[0, 0] == 1.0, "Terrain not setting values correctly.");
  86. x[0, 0] = 0;
  87. x[0, 0] += 5.0;
  88. x[0, 0] -= 1.0;
  89. Assert.That(x[0, 0] == 4.0, "Terrain addition/subtraction error.");
  90. x[0, 0] = Math.PI;
  91. double[,] doublesExport = x.GetDoubles();
  92. Assert.That(doublesExport[0, 0] == Math.PI, "Export to double[,] array not working correctly.");
  93. x[0, 0] = 1.0;
  94. float[] floatsExport = x.GetFloatsSerialised();
  95. Assert.That(floatsExport[0] == 1.0f, "Export to float[] not working correctly.");
  96. x[0, 0] = 1.0;
  97. Assert.That(x.Tainted(0, 0), "Terrain channel tainting not working correctly.");
  98. Assert.That(!x.Tainted(0, 0), "Terrain channel tainting not working correctly.");
  99. TerrainChannel y = x.Copy();
  100. Assert.That(!ReferenceEquals(x, y), "Terrain copy not duplicating correctly.");
  101. Assert.That(!ReferenceEquals(x.GetDoubles(), y.GetDoubles()), "Terrain array not duplicating correctly.");
  102. }
  103. }
  104. }