MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / test_forEach_self_pymethod

Function test_forEach_self_pymethod

tests/python/test_arrays.py:1018–1038  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1016
1017
1018def test_forEach_self_pymethod():
1019 items = ['Four', 'Three', 'One']
1020
1021 class Counter:
1022 def __init__(self):
1023 self.count = 0
1024
1025 def increment(self, element, index, array):
1026 self.count += 1
1027
1028 obj = Counter()
1029 assert obj.count == 0
1030 result = pm.eval("""
1031 (arr, increment, result) => {
1032 let jsObj = {count: 0}
1033 arr.forEach(increment, jsObj);
1034 return jsObj.count;
1035 }
1036 """)(items, obj.increment)
1037 assert obj.count == 0
1038 assert result == 3
1039
1040
1041def test_forEach_self_pyfunction():

Callers

nothing calls this directly

Calls 1

CounterClass · 0.85

Tested by

no test coverage detected