Refactored texture loading: added caching and allowed loading from RAM

This commit is contained in:
2020-07-31 14:42:28 +03:00
parent e8cec807bc
commit 16205909ed
11 changed files with 503 additions and 309 deletions

View File

@@ -0,0 +1,58 @@
package ru.windcorp.optica.util;
import static org.junit.Assert.assertEquals;
import java.util.Random;
import org.junit.Test;
import ru.windcorp.optica.common.util.BinUtil;
public class BinUtilTest {
@Test
public void cornerCases() {
test(1);
test(2);
test(3);
test(4);
test(7);
test(8);
test(9);
test(1023);
test(1024);
test(1025);
test((1 << 16) - 1);
test(1 << 16);
test((1 << 16) + 1);
}
@Test
public void random() {
Random random = new Random(0);
for (int i = 0; i < 10000; ++i) {
test(random.nextInt((1 << 30) - 2) + 1);
}
}
void test(int x) {
assertEquals("Round, x = " + x, referenceRound(x), BinUtil.roundToGreaterPowerOf2(x));
assertEquals("Greater, x = " + x, referenceGreater(x), BinUtil.closestGreaterPowerOf2(x));
}
int referenceGreater(int x) {
int p;
for (p = 1; p <= x; p *= 2);
return p;
}
int referenceRound(int x) {
int p;
for (p = 1; p < x; p *= 2);
return p;
}
}