Add additional DhSectionPos unit tests

This commit is contained in:
James Seibel
2023-09-13 21:52:56 -05:00
parent 5ee1bea7c0
commit 84236e7a31
+145 -2
View File
@@ -19,8 +19,7 @@
package tests;
import com.seibel.distanthorizons.core.pos.DhLodPos;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.pos.*;
import org.junit.Assert;
import org.junit.Test;
@@ -159,4 +158,148 @@ public class DhSectionPosTest
}
@Test
public void CreateFromBlockPos()
{
// origin pos //
DhBlockPos originBlockPos = new DhBlockPos(0, 0, 0);
DhSectionPos originSectionPos = new DhSectionPos(originBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhBlockPos offsetBlockPos = new DhBlockPos(1000, 0, 42000);
DhSectionPos offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
offsetBlockPos = new DhBlockPos(-987654, 0, 46);
offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
}
@Test
public void CreateFromBlockPos2D()
{
// origin pos //
DhBlockPos2D originBlockPos = new DhBlockPos2D(0, 0);
DhSectionPos originSectionPos = new DhSectionPos(originBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhBlockPos2D offsetBlockPos = new DhBlockPos2D(1000, 42000);
DhSectionPos offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
offsetBlockPos = new DhBlockPos2D(-987654, 46);
offsetSectionPos = new DhSectionPos(offsetBlockPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
}
@Test
public void CreateFromChunkPos()
{
// origin pos //
DhChunkPos originChunkPos = new DhChunkPos(0,0);
DhSectionPos originSectionPos = new DhSectionPos(originChunkPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhChunkPos offsetChunkPos = new DhChunkPos(1000, 42000);
DhSectionPos offsetSectionPos = new DhSectionPos(offsetChunkPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, 15, 656), offsetSectionPos);
offsetChunkPos = new DhChunkPos(-987654, 46);
offsetSectionPos = new DhSectionPos(offsetChunkPos);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_CHUNK_DETAIL_LEVEL, -15433, 0), offsetSectionPos);
}
@Test
public void ConvertToDetailLevel()
{
// origin pos //
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
originSectionPos = originSectionPos.convertToDetailLevel((byte) 1);
Assert.assertEquals(new DhSectionPos((byte) 1, 0, 0), originSectionPos);
originSectionPos = originSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, 0, 0), originSectionPos);
originSectionPos = originSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, 0, 0), originSectionPos);
// offset pos //
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
sectionPos = sectionPos.convertToDetailLevel((byte) 1);
Assert.assertEquals(new DhSectionPos((byte) 1, -5000, 2500), sectionPos);
sectionPos = sectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL, -157, 78), sectionPos);
sectionPos = sectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(new DhSectionPos(DhSectionPos.SECTION_REGION_DETAIL_LEVEL, -1, 0), sectionPos);
}
@Test
public void GetDefaultWidth()
{
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
// widths should be the same regardless of position in the world
originSectionPos = originSectionPos.convertToDetailLevel((byte) 1);
Assert.assertEquals(1, originSectionPos.getWidth().numberOfLodSectionsWide);
sectionPos = sectionPos.convertToDetailLevel((byte) 1);
Assert.assertEquals(1, sectionPos.getWidth().numberOfLodSectionsWide);
originSectionPos = originSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(1, originSectionPos.getWidth().numberOfLodSectionsWide);
sectionPos = sectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(1, sectionPos.getWidth().numberOfLodSectionsWide);
originSectionPos = originSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(1, originSectionPos.getWidth().numberOfLodSectionsWide);
sectionPos = sectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(1, sectionPos.getWidth().numberOfLodSectionsWide);
}
@Test
public void GetOffsetWidth()
{
DhSectionPos originSectionPos = new DhSectionPos((byte) 0,0,0);
DhSectionPos sectionPos = new DhSectionPos((byte) 0,-10000,5000);
originSectionPos = originSectionPos.convertToDetailLevel((byte) 1);
Assert.assertEquals(2, originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
sectionPos = sectionPos.convertToDetailLevel((byte) 1);
Assert.assertEquals(2, sectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
originSectionPos = originSectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, originSectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
sectionPos = sectionPos.convertToDetailLevel(DhSectionPos.SECTION_BLOCK_DETAIL_LEVEL);
Assert.assertEquals(64, sectionPos.getWidth((byte) 0).numberOfLodSectionsWide);
originSectionPos = originSectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(4096, originSectionPos.getWidth((byte) 3).numberOfLodSectionsWide);
sectionPos = sectionPos.convertToDetailLevel(DhSectionPos.SECTION_REGION_DETAIL_LEVEL);
Assert.assertEquals(4096, sectionPos.getWidth((byte) 3).numberOfLodSectionsWide);
}
}