Esempio n. 1
0
 def test_data(self):
     result = amply.Amply("param T := 4;")["T"]
     assert result == 4
     result = amply.Amply("param T := -4;")["T"]
     assert result == -4
     result = amply.Amply("param T := 0.04;")["T"]
     assert result == 0.04
     result = amply.Amply("param T := -0.04;")["T"]
     assert result == -0.04
Esempio n. 2
0
    def test_set(self):
        result = amply.Amply("set month := Jan Feb Mar Apr;")['month']
        assert result == ['Jan', 'Feb', 'Mar', 'Apr']

        result = amply.Amply("set month Jan Feb Mar Apr;")['month']
        assert result == ['Jan', 'Feb', 'Mar', 'Apr']
        assert [i for i in result] == ['Jan', 'Feb', 'Mar', 'Apr']
        assert result != []

        assert 'Jan' in result
        assert 'Foo' not in result
        assert len(result) == 4
Esempio n. 3
0
    def test_set(self):
        result = amply.Amply("set month := Jan Feb Mar Apr;")["month"]
        assert result == ["Jan", "Feb", "Mar", "Apr"]

        result = amply.Amply("set month Jan Feb Mar Apr;")["month"]
        assert result == ["Jan", "Feb", "Mar", "Apr"]
        assert [i for i in result] == ["Jan", "Feb", "Mar", "Apr"]
        assert result != []

        assert "Jan" in result
        assert "Foo" not in result
        assert len(result) == 4
Esempio n. 4
0
    def test_2d_param_defaults(self):
        result = amply.Amply("""
            param demand {item, location};
            param demand default 42
                :   FRA DET LAN :=
            spoons  200 . 30
            plates  30  120 .
            cups    . .  29 ;
            """)["demand"]

        options = [
            ("spoons", {
                "FRA": 200,
                "DET": 42,
                "LAN": 30
            }),
            ("plates", {
                "FRA": 30,
                "DET": 120,
                "LAN": 42
            }),
            ("cups", {
                "FRA": 42,
                "DET": 42,
                "LAN": 29
            }),
        ]
        for name, _dict in options:
            self.assertDictEqual(result[name], _dict)
Esempio n. 5
0
    def test_2d_param_transpose(self):
        result = amply.Amply("""
            param demand {location, item};
            param demand default 42 (tr)
                :   FRA DET LAN :=
            spoons  200 . 30
            plates  30  120 .
            cups    . .  29 ;
            """)["demand"]

        self.assertEqual(result["FRA"], {
            "spoons": 200,
            "plates": 30,
            "cups": 42
        })
        self.assertEqual(result["DET"], {
            "spoons": 42,
            "plates": 120,
            "cups": 42
        })
        self.assertEqual(result["LAN"], {
            "spoons": 30,
            "plates": 42,
            "cups": 29
        })
Esempio n. 6
0
 def test_set_splice(self):
     result = amply.Amply("""
         set A dimen 3;
         set A := (1, 2, 3), (1, 1, *) 2 4 (3, *, *) 1 1;
         """)
     a = result.A
     assert a == [(1, 2, 3), (1, 1, 2), (1, 1, 4), (3, 1, 1)]
Esempio n. 7
0
    def test_2d_param_transpose(self):
        result = amply.Amply("""
            param demand {location, item};
            param demand default 42 (tr)
                :   FRA DET LAN :=
            spoons  200 . 30
            plates  30  120 .
            cups    . .  29 ;
            """)['demand']

        self.assertEqual(result['FRA'], {
            'spoons': 200,
            'plates': 30,
            'cups': 42
        })
        self.assertEqual(result['DET'], {
            'spoons': 42,
            'plates': 120,
            'cups': 42
        })
        self.assertEqual(result['LAN'], {
            'spoons': 30,
            'plates': 42,
            'cups': 29
        })
Esempio n. 8
0
    def test_2d_param_defaults(self):
        result = amply.Amply("""
            param demand {item, location};
            param demand default 42
                :   FRA DET LAN :=
            spoons  200 . 30
            plates  30  120 .
            cups    . .  29 ;
            """)['demand']

        options = [('spoons', {
            'FRA': 200,
            'DET': 42,
            'LAN': 30
        }), ('plates', {
            'FRA': 30,
            'DET': 120,
            'LAN': 42
        }), ('cups', {
            'FRA': 42,
            'DET': 42,
            'LAN': 29
        })]
        for name, _dict in options:
            self.assertDictEqual(result[name], _dict)
Esempio n. 9
0
    def test_2d_param(self):
        result = amply.Amply("""
            param demand {item, location};
            param demand
                :   FRA DET LAN :=
            spoons  200 100 30
            plates  30  120 90
            cups    666 13  29 ;
            """)['demand']

        options = [('spoons', {
            'FRA': 200,
            'DET': 100,
            'LAN': 30
        }), ('plates', {
            'FRA': 30,
            'DET': 120,
            'LAN': 90
        }), ('cups', {
            'FRA': 666,
            'DET': 13,
            'LAN': 29
        })]
        for name, _dict in options:
            self.assertDictEqual(result[name], _dict)
Esempio n. 10
0
    def test_2d_param(self):
        result = amply.Amply("""
            param demand {item, location};
            param demand
                :   FRA DET LAN :=
            spoons  200 100 30
            plates  30  120 90
            cups    666 13  29 ;
            """)["demand"]

        options = [
            ("spoons", {
                "FRA": 200,
                "DET": 100,
                "LAN": 30
            }),
            ("plates", {
                "FRA": 30,
                "DET": 120,
                "LAN": 90
            }),
            ("cups", {
                "FRA": 666,
                "DET": 13,
                "LAN": 29
            }),
        ]
        for name, _dict in options:
            self.assertDictEqual(result[name], _dict)
Esempio n. 11
0
 def test_param_default(self):
     result = amply.Amply("""
         param foo {s} default 3;
         param foo := Jan 1 Feb 2 Mar 3;
         """)
     options = [('Jan', 1), ('Mar', 3), ('FOO', 3)]
     for name, value in options:
         self.assertEqual(result['foo'][name], value)
Esempio n. 12
0
 def test_param_default(self):
     result = amply.Amply("""
         param foo {s} default 3;
         param foo := Jan 1 Feb 2 Mar 3;
         """)
     options = [("Jan", 1), ("Mar", 3), ("FOO", 3)]
     for name, value in options:
         self.assertEqual(result["foo"][name], value)
Esempio n. 13
0
 def test_empty_parameter_statement(self):
     result = amply.Amply("""
         param square {x};
         param square default 99 :=
         ;
         """)
     assert "square" in result.symbols.keys()
     assert result.square == {}
Esempio n. 14
0
 def test_2d_slice1(self):
     result = amply.Amply("""
         param demand {location, item};
         param demand :=
             [Jan, *] Foo 1 Bar 2;
         """)['demand']
     f = result['Jan']['Foo']
     assert f == 1
     assert result['Jan']['Bar'] == 2
Esempio n. 15
0
 def test_param_undefined(self):
     result = amply.Amply("""
         param foo {s} ;
         param foo := Jan 1 Feb 2 Mar 3;
         """)
     j = result['foo']['Jan']
     assert j == 1
     with self.assertRaises(KeyError):
         a = result['foo']['Apr']
Esempio n. 16
0
 def test_sub1_params(self):
     result = amply.Amply("""
         param foo {s};
         param foo := 1 Jan 2 Feb 3 Mar;
         """)
     j = result['foo'][1]
     assert j == 'Jan'
     f = result['foo'][2]
     assert f == 'Feb'
Esempio n. 17
0
 def test_undefined_tabbing_param(self):
     a = """
         param cost{elem};
         param : cost value :=
         0       1   2
         3       4   5
         ;
         """
     self.assertRaises(amply.AmplyError, lambda: amply.Amply(a))
Esempio n. 18
0
 def test_2d_slice1(self):
     result = amply.Amply("""
         param demand {location, item};
         param demand :=
             [Jan, *] Foo 1 Bar 2;
         """)["demand"]
     f = result["Jan"]["Foo"]
     assert f == 1
     assert result["Jan"]["Bar"] == 2
Esempio n. 19
0
 def test_sub2_params(self):
     result = amply.Amply("""
         param foo {s, t};
         param foo := 1 2 Hi 99 3 4;
         """)
     h = result["foo"][1][2]
     assert h == "Hi"
     f = result["foo"][99][3]
     assert f == 4
Esempio n. 20
0
 def test_param_undefined(self):
     result = amply.Amply("""
         param foo {s} ;
         param foo := Jan 1 Feb 2 Mar 3;
         """)
     j = result["foo"]["Jan"]
     assert j == 1
     with self.assertRaises(KeyError):
         result["foo"]["Apr"]
Esempio n. 21
0
 def test_sub1_params(self):
     result = amply.Amply("""
         param foo {s};
         param foo := 1 Jan 2 Feb 3 Mar;
         """)
     j = result["foo"][1]
     assert j == "Jan"
     f = result["foo"][2]
     assert f == "Feb"
Esempio n. 22
0
 def test_load_file(self):
     a = amply.Amply("param T:= 4; param X{foo};")
     try:
         s = StringIO("param S := 6; param X := 1 2;")
     except TypeError:
         s = StringIO(u"param S := 6; param X := 1 2;")
     a.load_file(s)
     assert a.T == 4
     assert a.S == 6
     assert a.X[1] == 2
Esempio n. 23
0
    def test_empty_tabbing_parameter_statement(self):

        result = amply.Amply("""
            set x;
            param square {x};
            param default 99 : square :=
            ;
            """)
        assert 'square' in result.symbols.keys()
        assert result.square == {}
Esempio n. 24
0
 def test_set_subscript(self):
     result = amply.Amply("""
         set days{months};
         set days[Jan] := 1 2 3 4;
         set days[Feb] := 5 6 7 8;
         """)['days']
     j = result['Jan']
     assert j == [1, 2, 3, 4]
     f = result['Feb']
     assert f == [5, 6, 7, 8]
Esempio n. 25
0
 def test_set_subscript(self):
     result = amply.Amply("""
         set days{months};
         set days[Jan] := 1 2 3 4;
         set days[Feb] := 5 6 7 8;
         """)["days"]
     j = result["Jan"]
     assert j == [1, 2, 3, 4]
     f = result["Feb"]
     assert f == [5, 6, 7, 8]
Esempio n. 26
0
 def test_set_matrix(self):
     result = amply.Amply("""
         set A : 1 2 3 :=
             1   + - -
             2   + + -
             3   - + -
         ;
         """)
     a = result.A
     assert a == [(1, 1), (2, 1), (2, 2), (3, 2)]
Esempio n. 27
0
 def test_set_matrix_tr(self):
     result = amply.Amply("""
         set A (tr) : 1 2 3 :=
                  1   + - -
                  2   + + -
                  3   - + -
         ;
         """)
     a = result.A
     assert a == [(1, 1), (1, 2), (2, 2), (2, 3)]
Esempio n. 28
0
 def test_set_subscript2_tuples(self):
     result = amply.Amply("""
         set days{months, days};
         set days[Jan, 3] := 1 2 3 4;
         set days[Feb, 'Ham '] := 5 6 7 8;
         """)["days"]
     j = result["Jan", 3]
     assert j == [1, 2, 3, 4]
     f = result["Feb", "Ham "]
     assert f == [5, 6, 7, 8]
Esempio n. 29
0
 def test_set_subscript2_tuples(self):
     result = amply.Amply("""
         set days{months, days};
         set days[Jan, 3] := 1 2 3 4;
         set days[Feb, 'Ham '] := 5 6 7 8;
         """)['days']
     j = result['Jan', 3]
     assert j == [1, 2, 3, 4]
     f = result['Feb', 'Ham ']
     assert f == [5, 6, 7, 8]
Esempio n. 30
0
    def test_empty_tabbing_parameters(self):

        result = amply.Amply("""
            set x;
            param square {x};
            param triangle {x};
            param default 99 : square triangle :=
            ;
            """)
        assert "square" in result.symbols.keys()
        assert result.square == {}