File: WrappedBooleanTest.java

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (59 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.python.core;

import junit.framework.TestCase;

import org.python.util.PythonInterpreter;

public class WrappedBooleanTest extends TestCase {

    // Simulate the use case where you want to expose some (possibly mutable)
    // java boolean field to an interpreter without having to set the value to a
    // new PyBoolean each time it changes.
    @SuppressWarnings("serial")
    static class WrappedBoolean extends PyBoolean {
        public WrappedBoolean() {
            super(true);
        }

        private boolean mutableValue;

        @Override
        public boolean getBooleanValue() {
            return mutableValue;
        }

        public void setMutableValue(final boolean newValue) {
            mutableValue = newValue;
        }
    }

    private PythonInterpreter interp;
    private WrappedBoolean a, b;

    @Override
    protected void setUp() throws Exception {
        interp = new PythonInterpreter(new PyStringMap(), new PySystemState());
        a = new WrappedBoolean();
        b = new WrappedBoolean();
        a.setMutableValue(true);
        b.setMutableValue(false);
        interp.set("a", a);
        interp.set("b", b);
    }

    public void testAnd() {
        interp.exec("c = a and b");
        assertEquals(new PyBoolean(false), interp.get("c"));
        b.setMutableValue(true);
        interp.exec("c = a and b");
        assertEquals(new PyBoolean(true), interp.get("c"));
    }

    public void testOr() {
        interp.exec("c = a or b");
        assertEquals(new PyBoolean(true), interp.get("c"));
        a.setMutableValue(false);
        interp.exec("c = a or b");
        assertEquals(new PyBoolean(false), interp.get("c"));
    }
}