Files
LihonT-Store/tests/lihonstore/app/CutTest.java
cheb0chik e8277bb7e8 LihonT Store 0.1
A catalog app for the LihonT mod: avatar frames and chat bubbles made by members. Browse, add with the plus button, author profiles,
publishing with a check before anything is shown. Signs in through the TikTok that carries the mod, which hands over only the public
account data to an app signed with the same key.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-05 15:40:01 +03:00

50 lines
2.1 KiB
Java

package lihonstore.app;
import java.util.Arrays;
/** The pixel maths of the store's frames on a plain JVM. Usage: CutTest scenario; prints "PASS scenario". */
public final class CutTest {
private CutTest() {}
public static void main(String[] args) {
switch (args[0]) {
case "ring": ring(); break;
case "fit": fit(); break;
default: throw new IllegalArgumentException(args[0]);
}
System.out.println("PASS " + args[0]);
}
private static void check(boolean ok, String what) {
if (!ok) throw new AssertionError(what);
}
private static void ring() {
int side = Cut.SIDE;
int[] solid = new int[side * side];
Arrays.fill(solid, 0xFFCC3322);
check(!Cut.seeThroughMiddle(solid), "a solid picture is not a frame yet");
Cut.ring(solid);
check((solid[(side / 2) * side + side / 2] >>> 24) == 0, "the middle is a hole");
check((solid[0] >>> 24) == 0, "the corner is cut off");
check((solid[(side / 2) * side + (side - 12)] >>> 24) == 255, "the ring itself is kept");
check(Cut.seeThroughMiddle(solid), "a ring is a frame");
int[] before = solid.clone();
if (!Cut.seeThroughMiddle(solid)) Cut.ring(solid);
check(Arrays.equals(before, solid), "a frame is left as it is");
// the colour of what is kept does not change, only its opacity
int[] one = new int[side * side];
Arrays.fill(one, 0xFF123456);
Cut.ring(one);
check((one[(side / 2) * side + (side - 12)] & 0x00FFFFFF) == 0x123456, "colour kept");
}
private static void fit() {
check(Arrays.equals(Cut.fit(100, 80, 512), new int[] {100, 80}), "small pictures are not enlarged");
check(Arrays.equals(Cut.fit(1024, 512, 512), new int[] {512, 256}), "the longer side is scaled to the limit");
check(Arrays.equals(Cut.fit(500, 2000, 512), new int[] {128, 512}), "tall pictures too");
int[] thin = Cut.fit(10000, 3, 512);
check(thin[0] == 512 && thin[1] >= 3, "never a zero side");
}
}