Skip to content

Commit

Permalink
start adding expr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dromer committed Jul 19, 2023
1 parent 4609bff commit d4c5808
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hvcc/interpreters/pd2hv/PdExprObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from .PdObject import PdObject

from typing import Optional, List


class PdExprObject(PdObject):
"""
Expand All @@ -31,7 +33,13 @@ class PdExprObject(PdObject):
- skipped variables cause crash, like "$f1 + $f3"
"""

def __init__(self, obj_type, obj_args=None, pos_x=0, pos_y=0):
def __init__(
self,
obj_type: str,
obj_args: Optional[List] = None,
pos_x: int = 0,
pos_y: int = 0
) -> None:
"""
Validate the expr object and any heavy restrictions, then
convert it directly into a HeavyIR object.
Expand All @@ -40,7 +48,7 @@ def __init__(self, obj_type, obj_args=None, pos_x=0, pos_y=0):

print("In Pd expr Obj")
assert obj_type in ["expr", "expr~"]
super().__init__(self, obj_type, obj_args, pos_x, pos_y)
super().__init__(obj_type, obj_args, pos_x, pos_y)

# turn the arguments into a list of expressions, but only one for now
if len(self.obj_args) == 0:
Expand Down
1 change: 1 addition & 0 deletions tests/pd/control_expr/test-div.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[@ 0.000] print: 0.148387
16 changes: 16 additions & 0 deletions tests/pd/control_expr/test-div.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#N canvas 670 156 450 300 12;
#X obj 55 17 loadbang;
#X obj 55 152 print;
#X msg 116 77 3.1;
#X msg 55 77 2.3;
#X obj 55 42 t b b b;
#X msg 178 77 5.5;
#X obj 55 119 expr ($f1/$f2)/$i3;
#X connect 0 0 4 0;
#X connect 2 0 6 1;
#X connect 3 0 6 0;
#X connect 4 0 3 0;
#X connect 4 1 2 0;
#X connect 4 2 5 0;
#X connect 5 0 6 2;
#X connect 6 0 1 0;
1 change: 1 addition & 0 deletions tests/pd/control_expr/test-mult.golden.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[@ 0.000] print: 35.65
16 changes: 16 additions & 0 deletions tests/pd/control_expr/test-mult.pd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#N canvas 670 156 450 300 12;
#X obj 55 17 loadbang;
#X obj 55 152 print;
#X msg 109 77 3.1;
#X msg 55 77 2.3;
#X obj 55 119 expr $f1*$f2*$i3;
#X obj 55 42 t b b b;
#X msg 164 77 5.5;
#X connect 0 0 5 0;
#X connect 2 0 4 1;
#X connect 3 0 4 0;
#X connect 4 0 1 0;
#X connect 5 0 3 0;
#X connect 5 1 2 0;
#X connect 5 2 6 0;
#X connect 6 0 4 2;
50 changes: 50 additions & 0 deletions tests/test_control_expr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (C) 2014-2018 Enzien Audio, Ltd.
# Copyright (C) 2022 Wasted Audio
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import argparse
import os

from tests.framework.base_control import TestPdControlBase


class TestPdControlPatches(TestPdControlBase):
SCRIPT_DIR = os.path.dirname(__file__)
TEST_DIR = os.path.join(os.path.dirname(__file__), "pd", "control_expr")

def test_mult(self):
self._test_control_patch("test-mult.pd")

def test_div(self):
self._test_control_patch("test-div.pd")


def main():
# TODO(mhroth): make this work
parser = argparse.ArgumentParser(
description="Compile a specific pd patch.")
parser.add_argument(
"pd_path",
help="The path to the Pd file to read.")
args = parser.parse_args()
if os.path.exists(args.pd_path):
result = TestPdControlPatches._test_control_patch(args.pd_path)
print(result)
else:
print(f"Pd file path '{args.pd_path}' doesn't exist")


if __name__ == "__main__":
main()

0 comments on commit d4c5808

Please sign in to comment.