refactors
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.builder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BlockStatePlacementOptionTest {
|
||||
|
||||
@Test
|
||||
public void sanityCheck() {
|
||||
// standing at 1,0,0
|
||||
// block to be placed at 0,0,0
|
||||
// placing against 0,0,-1
|
||||
|
||||
// eye is at 1, 1.62, 0
|
||||
// north or west
|
||||
|
||||
StringBuilder sanity = new StringBuilder();
|
||||
for (PlayerVantage vantage : new PlayerVantage[]{PlayerVantage.STRICT_CENTER, PlayerVantage.LOOSE_CENTER}) {
|
||||
for (Face playerFacing : new Face[]{Face.NORTH, Face.EAST, Face.WEST}) {
|
||||
sanity.append(vantage).append(playerFacing);
|
||||
List<Raytracer.Raytrace> traces = BlockStatePlacementOption.get(Face.NORTH, Half.BOTTOM, Optional.of(playerFacing), Optional.empty()).computeTraceOptions(new PlaceAgainstData(Face.SOUTH, Half.EITHER, false), 1, 0, 0, vantage, 4);
|
||||
sanity.append(traces.size());
|
||||
sanity.append(" ");
|
||||
if (!traces.isEmpty()) {
|
||||
for (double d : new double[]{traces.get(0).playerEye.x, traces.get(0).playerEye.z}) {
|
||||
double base = d > 1 ? 1.5 : 0.5;
|
||||
boolean a = d == base - BlockStatePlacementOption.LOOSE_CENTER_DISTANCE;
|
||||
boolean b = d == base;
|
||||
boolean c = d == base + BlockStatePlacementOption.LOOSE_CENTER_DISTANCE;
|
||||
if (!a && !b && !c) {
|
||||
throw new IllegalStateException("Wrong " + d);
|
||||
}
|
||||
sanity.append(a).append(" ").append(b).append(" ").append(c).append(" ");
|
||||
}
|
||||
}
|
||||
sanity.append(traces.stream().mapToDouble(Raytracer.Raytrace::centerDistApprox).distinct().count());
|
||||
sanity.append(";");
|
||||
}
|
||||
}
|
||||
|
||||
String res = sanity.toString();
|
||||
String should = "STRICT_CENTERNORTH0 0;STRICT_CENTEREAST0 0;STRICT_CENTERWEST3 false true false false true false 1;LOOSE_CENTERNORTH2 true false false false true false 1;LOOSE_CENTEREAST0 0;LOOSE_CENTERWEST13 false true false false true false 2;";
|
||||
if (!res.equals(should)) {
|
||||
System.out.println(res);
|
||||
System.out.println(should);
|
||||
throw new IllegalStateException(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/test/java/baritone/builder/FaceTest.java
Normal file
32
src/test/java/baritone/builder/FaceTest.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.builder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class FaceTest {
|
||||
@Test
|
||||
public void testOpts() {
|
||||
for (int i = 0; i < Face.OPTS.size(); i++) {
|
||||
assertEquals(i, Face.OPTS.indexOf(Face.OPTS.get(i)));
|
||||
assertEquals(i, (int) Face.OPTS.get(i).map(face -> face.index).orElse(Face.NUM_FACES));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,40 +23,47 @@ import static org.junit.Assert.*;
|
||||
|
||||
public class PlayerPhysicsTest {
|
||||
|
||||
@Test
|
||||
public void testAssumptions() {
|
||||
if (Blip.PLAYER_HEIGHT_SLIGHT_OVERESTIMATE >= Blip.TWO_BLOCKS || Blip.PLAYER_HEIGHT_SLIGHT_OVERESTIMATE + Blip.HALF_BLOCK <= Blip.TWO_BLOCKS) {
|
||||
throw new IllegalStateException("Assumptions made in playerTravelCollides");
|
||||
}
|
||||
if (Blip.TALLEST_BLOCK - Blip.FULL_BLOCK + Blip.JUMP - Blip.TWO_BLOCKS >= 0) {
|
||||
throw new IllegalStateException("Assumption made in bidirectionalPlayerTravel");
|
||||
}
|
||||
int maxFeet = Blip.FULL_BLOCK - 1; // 15
|
||||
int couldJumpUpTo = maxFeet + Blip.JUMP; // 35
|
||||
int maxWithinAB = couldJumpUpTo - Blip.TWO_BLOCKS; // 3
|
||||
if (PlayerPhysics.protrudesIntoThirdBlock(maxWithinAB)) {
|
||||
// btw this is literally only 1 blip away from being true lol
|
||||
throw new IllegalStateException("Oh no, if this is true then playerTravelCollides needs to check another layer above EF");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic() {
|
||||
assertEquals(16, PlayerPhysics.highestCollision(BlockStateCachedData.SCAFFOLDING, BlockStateCachedData.SCAFFOLDING));
|
||||
assertEquals(16, PlayerPhysics.highestCollision(FakeStates.SCAFFOLDING, FakeStates.SCAFFOLDING));
|
||||
|
||||
Column normal = new Column();
|
||||
normal.underneath = BlockStateCachedData.SCAFFOLDING;
|
||||
normal.feet = BlockStateCachedData.AIR;
|
||||
normal.head = BlockStateCachedData.AIR;
|
||||
normal.above = BlockStateCachedData.AIR;
|
||||
normal.aboveAbove = BlockStateCachedData.SCAFFOLDING;
|
||||
normal.underneath = FakeStates.SCAFFOLDING;
|
||||
normal.feet = FakeStates.AIR;
|
||||
normal.head = FakeStates.AIR;
|
||||
normal.above = FakeStates.AIR;
|
||||
normal.aboveAbove = FakeStates.SCAFFOLDING;
|
||||
normal.init();
|
||||
|
||||
Column up = new Column();
|
||||
up.underneath = BlockStateCachedData.SCAFFOLDING;
|
||||
up.feet = BlockStateCachedData.SCAFFOLDING;
|
||||
up.head = BlockStateCachedData.AIR;
|
||||
up.above = BlockStateCachedData.AIR;
|
||||
up.aboveAbove = BlockStateCachedData.SCAFFOLDING;
|
||||
up.underneath = FakeStates.SCAFFOLDING;
|
||||
up.feet = FakeStates.SCAFFOLDING;
|
||||
up.head = FakeStates.AIR;
|
||||
up.above = FakeStates.AIR;
|
||||
up.aboveAbove = FakeStates.SCAFFOLDING;
|
||||
up.init();
|
||||
|
||||
assertEquals(PlayerPhysics.Collision.VOXEL_LEVEL, PlayerPhysics.playerTravelCollides(normal, normal));
|
||||
assertEquals(PlayerPhysics.Collision.JUMP_TO_VOXEL_UP, PlayerPhysics.playerTravelCollides(normal, up));
|
||||
}
|
||||
|
||||
private static final BlockStateCachedData[] BY_HEIGHT;
|
||||
|
||||
static {
|
||||
BY_HEIGHT = new BlockStateCachedData[Blip.FULL_BLOCK + 1];
|
||||
for (int height = 1; height <= Blip.FULL_BLOCK; height++) {
|
||||
BY_HEIGHT[height] = new BlockStateCachedData(new BlockStateCachedDataBuilder().collidesWithPlayer(true).fullyWalkableTop().collisionHeight(height * Blip.RATIO));
|
||||
}
|
||||
BY_HEIGHT[0] = BlockStateCachedData.AIR;
|
||||
}
|
||||
|
||||
private static BlockStateCachedData[] makeColToHeight(int height) {
|
||||
height += Blip.FULL_BLOCK * 3; // i don't truck with negative division / modulo
|
||||
if (height < 0) {
|
||||
@@ -65,11 +72,11 @@ public class PlayerPhysicsTest {
|
||||
int fullBlocks = height / Blip.FULL_BLOCK;
|
||||
BlockStateCachedData[] ret = new BlockStateCachedData[7];
|
||||
for (int i = 0; i < fullBlocks; i++) {
|
||||
ret[i] = BlockStateCachedData.SCAFFOLDING;
|
||||
ret[i] = FakeStates.SCAFFOLDING;
|
||||
}
|
||||
ret[fullBlocks] = BY_HEIGHT[height % Blip.FULL_BLOCK];
|
||||
ret[fullBlocks] = FakeStates.BY_HEIGHT[height % Blip.FULL_BLOCK];
|
||||
for (int i = fullBlocks + 1; i < ret.length; i++) {
|
||||
ret[i] = BlockStateCachedData.AIR;
|
||||
ret[i] = FakeStates.AIR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -102,7 +109,7 @@ public class PlayerPhysicsTest {
|
||||
for (int startCeil = 5; startCeil <= 7; startCeil++) {
|
||||
BlockStateCachedData[] fromCol = makeColToHeight(startHeight);
|
||||
if (startCeil < fromCol.length) {
|
||||
fromCol[startCeil] = BlockStateCachedData.SCAFFOLDING;
|
||||
fromCol[startCeil] = FakeStates.SCAFFOLDING;
|
||||
}
|
||||
Column from = toCol(fromCol);
|
||||
assertEquals(!from.standing(), startCeil == 5 && startHeight > 3);
|
||||
@@ -115,7 +122,7 @@ public class PlayerPhysicsTest {
|
||||
for (int endCeil = 5; endCeil <= 7; endCeil++) {
|
||||
BlockStateCachedData[] toCol = makeColToHeight(endHeight);
|
||||
if (endCeil < toCol.length) {
|
||||
toCol[endCeil] = BlockStateCachedData.SCAFFOLDING;
|
||||
toCol[endCeil] = FakeStates.SCAFFOLDING;
|
||||
}
|
||||
Column to = toCol(toCol);
|
||||
int endVoxel = (endHeight + Blip.FULL_BLOCK * 10) / Blip.FULL_BLOCK - 10; // hate negative division rounding to zero, punch negative division rounding to zero
|
||||
@@ -160,7 +167,7 @@ public class PlayerPhysicsTest {
|
||||
if (j >= 0 && j < col.length) {
|
||||
ret[i] = col[j];
|
||||
} else {
|
||||
ret[i] = BlockStateCachedData.OUT_OF_BOUNDS;
|
||||
ret[i] = FakeStates.OUT_OF_BOUNDS;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
27
src/test/java/baritone/builder/TarjansAlgorithmTest.java
Normal file
27
src/test/java/baritone/builder/TarjansAlgorithmTest.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.builder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TarjansAlgorithmTest {
|
||||
@Test
|
||||
public void test() {
|
||||
// the correctness test is already in there just gotta ask for it
|
||||
}
|
||||
}
|
||||
27
src/test/java/baritone/builder/TestCuboidBounds.java
Normal file
27
src/test/java/baritone/builder/TestCuboidBounds.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.builder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestCuboidBounds {
|
||||
@Test
|
||||
public void testBounds() {
|
||||
new CuboidBounds(10, 10, 10).sanityCheck();
|
||||
}
|
||||
}
|
||||
32
src/test/java/baritone/builder/Vec3dTest.java
Normal file
32
src/test/java/baritone/builder/Vec3dTest.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Baritone.
|
||||
*
|
||||
* Baritone is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Baritone is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.builder;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class Vec3dTest {
|
||||
@Test
|
||||
public void testFlatDir() {
|
||||
for (Face face : Face.HORIZONTALS) {
|
||||
Face flat = new Vec3d(face.x, face.y, face.z).flatDirection();
|
||||
assertEquals(flat, face);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,9 @@ public class ConnGraphTest {
|
||||
|
||||
@Test
|
||||
public void testPerformanceOnRepeatedConnectionAndDisconnection() {
|
||||
if (true) {
|
||||
return; // slow
|
||||
}
|
||||
EulerTourForest.sanityCheck2();
|
||||
EulerTourForest.sanityCheck();
|
||||
for (int trial = 0; trial < 1; trial++) {
|
||||
|
||||
Reference in New Issue
Block a user