RandomIODevice.java

1
// Copyright © 2004-2006 University of Helsinki, Department of Computer Science
2
// Copyright © 2012 various contributors
3
// This software is released under GNU Lesser General Public License 2.1.
4
// The license text is at http://www.gnu.org/licenses/lgpl-2.1.html
5
6
package fi.helsinki.cs.titokone.devices;
7
8
import fi.helsinki.cs.titokone.IODevice;
9
10
import java.security.SecureRandom;
11
import java.util.Random;
12
13
/**
14
 * a device which returns random numbers secure randoms by default
15
 * and pseudorandoms if you give a seed.
16
 */
17
public class RandomIODevice
18
        implements IODevice {
19 2
    protected Random rnd = new SecureRandom();
20
21
    public int getPortCount() {
22 3
        return 1;
23
    }
24
25
    @Override
26
    public int getPort(int n) {
27 1
        if (n == 0) {
28 2
            return rnd.nextInt();
29
        }
30 5
        throw new RuntimeException("should not be possible " + n);
31
    }
32
33
    @Override
34
    public void setPort(int n, int value) {
35 1
        if (n == 0) {
36 2
            rnd = new Random(value);
37
            return;
38
        }
39 5
        throw new RuntimeException("should not be possible " + n);
40
    }
41
42
    public void reset() {
43 2
        rnd = new SecureRandom();
44
    }
45
46
    public void update() {
47
    }
48
}

Mutations

19

removed call to java/security/SecureRandom::<init> : SURVIVED

Removed assignment to member variable rnd : SURVIVED

22

Substituted 1 with 0 : SURVIVED

replaced return of integer sized value with (x == 0 ? 1 : 0) : SURVIVED

Substituted 1 with 0 : SURVIVED

27

negated conditional : NO_COVERAGE

28

removed call to java/util/Random::nextInt : NO_COVERAGE

replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE

30

removed call to java/lang/StringBuilder::toString : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

removed call to java/lang/RuntimeException::<init> : NO_COVERAGE

removed call to java/lang/StringBuilder::<init> : NO_COVERAGE

35

negated conditional : NO_COVERAGE

36

removed call to java/util/Random::<init> : NO_COVERAGE

Removed assignment to member variable rnd : NO_COVERAGE

39

removed call to java/lang/StringBuilder::toString : NO_COVERAGE

removed call to java/lang/StringBuilder::<init> : NO_COVERAGE

removed call to java/lang/RuntimeException::<init> : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

removed call to java/lang/StringBuilder::append : NO_COVERAGE

43

removed call to java/security/SecureRandom::<init> : SURVIVED

Removed assignment to member variable rnd : SURVIVED

Active mutators

Tests examined


Report generated by PIT 0.27