SnapshotArrays.java

1
package com.rox.cartridge;
2
3
/** Copy helpers shared by the mappers' {@code snapshot()}/{@code restore()} - see {@link MapperSnapshot}. */
4
final class SnapshotArrays {
5
    private static final int[] NONE = new int[0];
6
7
    private SnapshotArrays(){
8
    }
9
10
    /** A copy of {@code array}, or an empty array for a board that doesn't have one (e.g. CHR-RAM on a CHR-ROM board). */
11
    static int[] copyOf(final int[] array){
12 2 1. copyOf : negated conditional → KILLED
2. copyOf : replaced return value with null for com/rox/cartridge/SnapshotArrays::copyOf → KILLED
        return array == null ? NONE.clone() : array.clone();
13
    }
14
15
    /**
16
     * Checks {@code from} could be copied into {@code into} ({@code null} meaning "this board has none",
17
     * matched by an empty {@code from}) - without copying, so a whole snapshot can be checked before
18
     * any of it is applied.
19
     *
20
     * @throws IllegalArgumentException if the sizes don't match, i.e. the snapshot is from a different board
21
     */
22
    static void requireSameSize(final int[] from, final int[] into, final String what){
23 1 1. requireSameSize : negated conditional → KILLED
        final int expected = into == null ? 0 : into.length;
24 1 1. requireSameSize : negated conditional → KILLED
        if (from.length != expected){
25
            throw new IllegalArgumentException("Expected " + expected + " bytes of " + what + ", got " + from.length);
26
        }
27
    }
28
29
    /** Copies {@code from} into {@code into}, once {@link #requireSameSize} has passed; nothing to copy if {@code into} is {@code null}. */
30
    static void copy(final int[] from, final int[] into){
31 1 1. copy : negated conditional → KILLED
        if (into != null){
32 1 1. copy : removed call to java/lang/System::arraycopy → KILLED
            System.arraycopy(from, 0, into, 0, from.length);
33
        }
34
    }
35
36
    static <T extends MapperSnapshot> T expect(final MapperSnapshot snapshot, final Class<T> type){
37 1 1. expect : negated conditional → KILLED
        if (!type.isInstance(snapshot)){
38
            throw new IllegalArgumentException("Can't restore a " + snapshot.getClass().getSimpleName() + " into a " + type.getSimpleName() + "'s mapper");
39
        }
40 1 1. expect : replaced return value with null for com/rox/cartridge/SnapshotArrays::expect → KILLED
        return type.cast(snapshot);
41
    }
42
}

Mutations

12

1.1
Location : copyOf
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
negated conditional → KILLED

2.2
Location : copyOf
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
replaced return value with null for com/rox/cartridge/SnapshotArrays::copyOf → KILLED

23

1.1
Location : requireSameSize
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
negated conditional → KILLED

24

1.1
Location : requireSameSize
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
negated conditional → KILLED

31

1.1
Location : copy
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
negated conditional → KILLED

32

1.1
Location : copy
Killed by : com.rox.cartridge.ChrMemoryTest.[engine:junit-jupiter]/[class:com.rox.cartridge.ChrMemoryTest]/[method:chrRamSnapshotsAreCopiesThatRestore()]
removed call to java/lang/System::arraycopy → KILLED

37

1.1
Location : expect
Killed by : com.rox.cartridge.MapperSnapshotTest.[engine:junit-jupiter]/[class:com.rox.cartridge.MapperSnapshotTest]/[method:restoreCopiesRatherThanKeepingTheSnapshotsArrays()]
negated conditional → KILLED

40

1.1
Location : expect
Killed by : com.rox.cartridge.MapperSnapshotTest.[engine:junit-jupiter]/[class:com.rox.cartridge.MapperSnapshotTest]/[method:restoreRejectsTheWrongPrgRamSize()]
replaced return value with null for com/rox/cartridge/SnapshotArrays::expect → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1