RAM.java

1
package com.rox.mem;
2
3
import static com.rox.ByteUtil.BYTE_MASK;
4
5
public class RAM implements Memory {
6
    private final int[] memory;
7
    /** What this RAM is called in error messages, e.g. {@code PRG-RAM}. */
8
    private final String name;
9
10
    public RAM(final int size) {
11
        this(size, "RAM");
12
    }
13
14
    public RAM(final int size, final String name) {
15 1 1. <init> : negated conditional → KILLED
        if (Integer.bitCount(size) != 1) {
16
            throw new IllegalArgumentException(
17
                    name + " size must be power of two");
18
        }
19
        this.memory = new int[size];
20
        this.name = name;
21
    }
22
23
    @Override
24
    public int read(final int address) {
25 4 1. read : Replaced bitwise AND with OR → KILLED
2. read : replaced int return with 0 for com/rox/mem/RAM::read → KILLED
3. read : Replaced integer subtraction with addition → KILLED
4. read : Replaced bitwise AND with OR → KILLED
        return memory[address & (memory.length - 1)] & BYTE_MASK;
26
    }
27
28
    @Override
29
    public void write(final int address, final int value) {
30 3 1. write : Replaced bitwise AND with OR → KILLED
2. write : Replaced integer subtraction with addition → KILLED
3. write : Replaced bitwise AND with OR → KILLED
        memory[address & (memory.length - 1)] = value & BYTE_MASK;
31
    }
32
33
    /** A copy of every byte, for a save state. */
34
    public int[] snapshot() {
35 1 1. snapshot : replaced return value with null for com/rox/mem/RAM::snapshot → KILLED
        return memory.clone();
36
    }
37
38
    /**
39
     * Checks {@code contents} could be {@link #restore}d, without changing anything.
40
     *
41
     * @throws IllegalArgumentException if {@code contents} isn't exactly this RAM's size
42
     */
43
    public void checkRestorable(final int[] contents) {
44 1 1. checkRestorable : negated conditional → KILLED
        if (contents.length != memory.length) {
45
            throw new IllegalArgumentException(
46
                    "Expected " + memory.length + " bytes of " + name + ", got " + contents.length);
47
        }
48
    }
49
50
    /**
51
     * Overwrites every byte with {@code contents} (copied, not kept) - the counterpart of {@link #snapshot()}.
52
     *
53
     * @throws IllegalArgumentException if {@code contents} isn't exactly this RAM's size
54
     */
55
    public void restore(final int[] contents) {
56 1 1. restore : removed call to com/rox/mem/RAM::checkRestorable → KILLED
        checkRestorable(contents);
57 2 1. restore : negated conditional → KILLED
2. restore : changed conditional boundary → KILLED
        for (int i = 0; i < memory.length; i++) {
58 1 1. restore : Replaced bitwise AND with OR → KILLED
            memory[i] = contents[i] & BYTE_MASK;
59
        }
60
    }
61
}

Mutations

15

1.1
Location : <init>
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
negated conditional → KILLED

25

1.1
Location : read
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
Replaced bitwise AND with OR → KILLED

2.2
Location : read
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
replaced int return with 0 for com/rox/mem/RAM::read → KILLED

3.3
Location : read
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
Replaced integer subtraction with addition → KILLED

4.4
Location : read
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
Replaced bitwise AND with OR → KILLED

30

1.1
Location : write
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
Replaced bitwise AND with OR → KILLED

2.2
Location : write
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
Replaced integer subtraction with addition → KILLED

3.3
Location : write
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[test-template:testReadFromBeyondMaxAddress(int, int, int)]/[test-template-invocation:#3]
Replaced bitwise AND with OR → KILLED

35

1.1
Location : snapshot
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[method:snapshotIsACopyNotALiveView()]
replaced return value with null for com/rox/mem/RAM::snapshot → KILLED

44

1.1
Location : checkRestorable
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[method:restoreRejectsTheWrongSize()]
negated conditional → KILLED

56

1.1
Location : restore
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[method:restoreRejectsTheWrongSize()]
removed call to com/rox/mem/RAM::checkRestorable → KILLED

57

1.1
Location : restore
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[method:restoreCopiesRatherThanKeepingTheCallersArray()]
negated conditional → KILLED

2.2
Location : restore
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[method:restoreCopiesRatherThanKeepingTheCallersArray()]
changed conditional boundary → KILLED

58

1.1
Location : restore
Killed by : com.rox.mem.RAMTest.[engine:junit-jupiter]/[class:com.rox.mem.RAMTest]/[method:restoreCopiesRatherThanKeepingTheCallersArray()]
Replaced bitwise AND with OR → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1