Skip to content

Commit

Permalink
tests were fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Jan 14, 2025
1 parent 49dfa74 commit c75f955
Show file tree
Hide file tree
Showing 20 changed files with 568 additions and 583 deletions.
10 changes: 5 additions & 5 deletions jac/examples/reference/architypes.jac
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ can print_base_classes(cls: type) -> type {
return cls;
}

class Animal {}
obj Animal {}

obj Domesticated {}

@print_base_classes
node Pet :Animal, Domesticated: {}
obj Pet :Animal, Domesticated: {}

walker Person :Animal: {}
obj Person :Animal: {}

walker Feeder :Person: {}
obj Feeder :Person: {}

@print_base_classes
walker Zoologist :Feeder: {}
obj Zoologist :Feeder: {}
89 changes: 66 additions & 23 deletions jac/examples/reference/architypes.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,90 @@
from jaclang.plugin.feature import JacFeature as jac
from __future__ import annotations
from jaclang import *


def print_base_classes(cls: type) -> type:
print(f"Base classes of {cls.__name__}: {[c.__name__ for c in cls.__bases__]}")
print(
f"Base classes of {cls.__name__}: {List([c.__name__ for c in cls.__bases__])}"
)
return cls


# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
# we need a base class.
#
# reference: https://stackoverflow.com/a/9639512/10846399
#
class Base:
class Animal(Obj):
pass


@jac.make_obj(on_entry=[], on_exit=[])
class Animal(Base):
pass


@jac.make_obj(on_entry=[], on_exit=[])
class Domesticated(jac.Obj):
class Domesticated(Obj):
pass


@print_base_classes
@jac.make_node(on_entry=[], on_exit=[])
class Pet(Animal, Domesticated, jac.Node):
class Pet(Animal, Domesticated, Obj):
pass


@jac.make_walker(on_entry=[], on_exit=[])
class Person(Animal, jac.Walker):
class Person(Animal, Obj):
pass


@jac.make_walker(on_entry=[], on_exit=[])
class Feeder(Person, jac.Walker):
class Feeder(Person, Obj):
pass


@print_base_classes
@jac.make_walker(on_entry=[], on_exit=[])
class Zoologist(Feeder, jac.Walker):
class Zoologist(Feeder, Obj):
pass


#
#
# (thakee): I guess I can remove the bellow code.
#
#

# from jaclang.plugin.feature import JacFeature as jac


# def print_base_classes(cls: type) -> type:
# print(f"Base classes of {cls.__name__}: {[c.__name__ for c in cls.__bases__]}")
# return cls


# # Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
# # we need a base class.
# #
# # reference: https://stackoverflow.com/a/9639512/10846399
# #
# class Base:
# pass


# @jac.make_obj(on_entry=[], on_exit=[])
# class Animal(Base):
# pass


# @jac.make_obj(on_entry=[], on_exit=[])
# class Domesticated(jac.Obj):
# pass


# @print_base_classes
# @jac.make_node(on_entry=[], on_exit=[])
# class Pet(Animal, Domesticated, jac.Node):
# pass


# @jac.make_walker(on_entry=[], on_exit=[])
# class Person(Animal, jac.Walker):
# pass


# @jac.make_walker(on_entry=[], on_exit=[])
# class Feeder(Person, jac.Walker):
# pass


# @print_base_classes
# @jac.make_walker(on_entry=[], on_exit=[])
# class Zoologist(Feeder, jac.Walker):
# pass
4 changes: 3 additions & 1 deletion jac/examples/reference/builtin_types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from jaclang import List

a = 9.2
b = 44
c = [2, 4, 6, 10]
c = List([2, 4, 6, 10]) # (thakee):
d = {"name": "john", "age": 28}
e = ("jaseci", 5, 4, 14)
f = True
Expand Down
10 changes: 5 additions & 5 deletions jac/examples/reference/check_statements.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from __future__ import annotations
from jaclang.plugin.feature import JacFeature as _Jac
from jaclang.plugin.feature import JacFeature as Jac

a = 5
b = 2


@_Jac.create_test
@Jac.create_test
def test_test1(check) -> None:
check.assertAlmostEqual(a, 6)


@_Jac.create_test
@Jac.create_test
def test_test2(check) -> None:
check.assertTrue(a != b)


@_Jac.create_test
@Jac.create_test
def test_test3(check) -> None:
check.assertIn("d", "abc")


@_Jac.create_test
@Jac.create_test
def test_test4(check) -> None:
check.assertEqual(a - b, 3)
8 changes: 4 additions & 4 deletions jac/examples/reference/data_spatial_walker_statements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from jaclang.plugin.feature import JacFeature as _Jac
from jaclang.plugin.feature import JacFeature as Jac


# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
Expand All @@ -11,13 +11,13 @@ class Base:
pass


@_Jac.make_walker(on_entry=[_Jac.DSFunc("self_destruct", None)], on_exit=[])
@Jac.make_walker(on_entry=[Jac.DSFunc("self_destruct", None)], on_exit=[])
class Visitor(Base):
def self_destruct(self, _jac_here_) -> None:
print("get's here")
_Jac.disengage(self)
Jac.disengage(self)
return
print("but not here")


_Jac.spawn_call(_Jac.get_root(), Visitor())
Jac.spawn_call(Jac.get_root(), Visitor())
20 changes: 10 additions & 10 deletions jac/examples/reference/disengage_statements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from jaclang.plugin.feature import JacFeature as _Jac
from jaclang.plugin.feature import JacFeature as Jac


# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
Expand All @@ -11,27 +11,27 @@ class Base:
pass


@_Jac.make_walker(on_entry=[_Jac.DSFunc("travel", _Jac.get_root_type())], on_exit=[])
@Jac.make_walker(on_entry=[Jac.DSFunc("travel", Jac.get_root_type())], on_exit=[])
class Visitor(Base):
def travel(self, _jac_here_: _Jac.get_root_type()) -> None:
if _Jac.visit_node(
self, _Jac.edge_ref(_jac_here_, None, _Jac.EdgeDir.OUT, None, None)
def travel(self, _jac_here_: Jac.get_root_type()) -> None:
if Jac.visit_node(
self, Jac.edge_ref(_jac_here_, None, Jac.EdgeDir.OUT, None, None)
):
pass
elif _Jac.visit_node(self, _Jac.get_root()):
elif Jac.visit_node(self, Jac.get_root()):
pass


@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[])
@Jac.make_node(on_entry=[Jac.DSFunc("speak", Visitor)], on_exit=[])
class item(Base):
def speak(self, _jac_here_: Visitor) -> None:
print("Hey There!!!")
_Jac.disengage(_jac_here_)
Jac.disengage(_jac_here_)
return


i = 0
while i < 5:
_Jac.connect(_Jac.get_root(), item(), _Jac.build_edge(_Jac.EdgeDir.OUT, None, None))
Jac.connect(Jac.get_root(), item(), Jac.build_edge(Jac.EdgeDir.OUT, None, None))
i += 1
_Jac.spawn_call(_Jac.get_root(), Visitor())
Jac.spawn_call(Jac.get_root(), Visitor())
18 changes: 9 additions & 9 deletions jac/examples/reference/visit_statements.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from jaclang.plugin.feature import JacFeature as _Jac
from jaclang.plugin.feature import JacFeature as Jac


# Since the Animal class cannot be inherit from object, (cause the base class will be changed at run time)
Expand All @@ -11,25 +11,25 @@ class Base:
pass


@_Jac.make_walker(on_entry=[_Jac.DSFunc("travel", _Jac.get_root_type())], on_exit=[])
@Jac.make_walker(on_entry=[Jac.DSFunc("travel", Jac.get_root_type())], on_exit=[])
class Visitor(Base):
def travel(self, _jac_here_: _Jac.get_root_type()) -> None:
if _Jac.visit_node(
self, _Jac.edge_ref(_jac_here_, None, _Jac.EdgeDir.OUT, None, None)
def travel(self, _jac_here_: Jac.get_root_type()) -> None:
if Jac.visit_node(
self, Jac.edge_ref(_jac_here_, None, Jac.EdgeDir.OUT, None, None)
):
pass
elif _Jac.visit_node(self, _Jac.get_root()):
elif Jac.visit_node(self, Jac.get_root()):
pass


@_Jac.make_node(on_entry=[_Jac.DSFunc("speak", Visitor)], on_exit=[])
@Jac.make_node(on_entry=[Jac.DSFunc("speak", Visitor)], on_exit=[])
class item(Base):
def speak(self, _jac_here_: Visitor) -> None:
print("Hey There!!!")


i = 0
while i < 5:
_Jac.connect(_Jac.get_root(), item(), _Jac.build_edge(_Jac.EdgeDir.OUT, None, None))
Jac.connect(Jac.get_root(), item(), Jac.build_edge(Jac.EdgeDir.OUT, None, None))
i += 1
_Jac.spawn_call(_Jac.get_root(), Visitor())
Jac.spawn_call(Jac.get_root(), Visitor())
Loading

0 comments on commit c75f955

Please sign in to comment.