Skip to content

Commit

Permalink
Merge pull request #536 from wdednam/pythoniseRegTest
Browse files Browse the repository at this point in the history
pythonised simpleIntegrationTest
  • Loading branch information
highperformancecoder authored Dec 18, 2024
2 parents ea65e63 + 2076700 commit 3d355e0
Showing 1 changed file with 72 additions and 53 deletions.
125 changes: 72 additions & 53 deletions test/00/simpleIntegrationTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,78 @@ pass()

trap "fail" 1 2 3 15

cat >input.tcl <<EOF
source $here/test/assert.tcl
# arrange for the following code to executed after Minsky has started.
proc afterMinskyStarted {} {
# remove Destroy binding as it interferes with assert
bind . <Destroy> {}
minsky.load $here/examples/exponentialGrowth.mky
getValue :y
assert {[value.value]==1}
set item "minsky.canvas.item"
findObject VarConstant
set a [\$item.value]
assert {[minsky.canvas.item.value]!=0}
# setting this flag prevents an extra reset occurring - used to
# distinguish between static plot updates and simulation
running 1
minsky.reset
step
step
getValue :y
assert {[value.value]>0}
if {\$a<0} {
assert {[value.value]>0 && [value.value]<1}
} else {
assert {[value.value]>0 && [value.value]>1}
}
set v [value.value]
findObject IntOp
\$item.toggleCoupled
minsky.reset
step
step
getValue :y
if {\$a<0} {
assert {[value.value]>0 && [value.value]<1}
} else {
assert {[value.value]>0 && [value.value]>1}
}
assert "\[value.value\]==\$v"
tcl_exit
}
cat >input.py <<EOF
import sys
sys.path.insert(0, '$here')
from pyminsky import minsky, findObject
# Step 1: Function to access value by ID
def getValue(valueId):
try:
# Access valueId directly via minsky's interface
value = minsky.variableValues[valueId]
print(f"Found variable {valueId} with value: {value.value()}")
return value
except KeyError:
raise ValueError(f"Variable '{valueId}' not found in variableValues.")
except Exception as e:
raise ValueError(f"Error accessing variable '{valueId}': {e}")
# Load the model
minsky.load('$here/examples/exponentialGrowth.mky')
# Step 2: Verify initial value of ':y'
y_value = getValue(":y")
assert y_value.value() == 1, f"Expected initial value of :y to be 1, but got {y_value.value()}"
# Step 3: Find and check VarConstant
findObject("VarConstant")
var_constant_value = minsky.canvas.item.value()
assert var_constant_value != 0, "VarConstant item value is unexpectedly 0."
print(f"VarConstant value: {var_constant_value}")
# Step 4: Advance simulation and verify updated ':y'
def step():
"""Advance the simulation by one step."""
minsky.step()
# Run two simulation steps
minsky.running = True
minsky.reset()
step()
step()
y_value_after_step = getValue(":y")
assert y_value_after_step.value() > 0, "Value of :y after steps is not greater than 0."
# Conditional check based on VarConstant value
if var_constant_value < 0:
assert 0 < y_value_after_step.value() < 1, "Expected :y to be between 0 and 1 for negative VarConstant."
else:
assert y_value_after_step.value() > 1, "Expected :y to be greater than 1 for positive VarConstant."
stored_y_value = y_value_after_step.value()
# Step 5: Toggle coupling for IntOp
findObject("IntOp")
minsky.canvas.item.toggleCoupled()
print("Toggled coupled state for IntOp.")
# Step 6: Reset and rerun simulation
minsky.reset()
step()
step()
y_value_after_toggle = getValue(":y")
if var_constant_value < 0:
assert 0 < y_value_after_toggle.value() < 1, "Expected :y to be between 0 and 1 for negative VarConstant."
else:
assert y_value_after_toggle.value() > 1, "Expected :y to be greater than 1 for positive VarConstant."
assert y_value_after_toggle.value() == stored_y_value, "Value of :y does not match after toggling coupled state."
EOF
$here/gui-tk/minsky input.tcl
if test $? -ne 0; then fail; fi

python3 input.py
if [ $? -ne 0 ]; then fail; fi

pass

0 comments on commit 3d355e0

Please sign in to comment.