-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into gruntz_demo
- Loading branch information
Showing
311 changed files
with
3,702 additions
and
1,005 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from lpython import i32,f64 | ||
from math import sqrt | ||
|
||
class coord: | ||
def __init__(self: "coord"): | ||
self.x: i32 = 3 | ||
self.y: i32 = 4 | ||
|
||
def main(): | ||
p1: coord = coord() | ||
sq_dist : i32 = p1.x*p1.x + p1.y*p1.y | ||
dist : f64 = sqrt(f64(sq_dist)) | ||
print("Squared Distance from origin = ", sq_dist) | ||
assert sq_dist == 25 | ||
print("Distance from origin = ", dist) | ||
assert dist == f64(5) | ||
print("p1.x = 6") | ||
print("p1.y = 8") | ||
p1.x = i32(6) | ||
p1.y = 8 | ||
sq_dist = p1.x*p1.x + p1.y*p1.y | ||
dist = sqrt(f64(sq_dist)) | ||
print("Squared Distance from origin = ", sq_dist) | ||
assert sq_dist == 100 | ||
print("Distance from origin = ", dist) | ||
assert dist == f64(10) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
def test_for_dict_int(): | ||
dict_int: dict[i32, i32] = {1:2, 2:3, 3:4} | ||
key: i32 | ||
s1: i32 = 0 | ||
s2: i32 = 0 | ||
|
||
for key in dict_int: | ||
print(key) | ||
s1 += key | ||
s2 += dict_int[key] | ||
|
||
assert s1 == 6 | ||
assert s2 == 9 | ||
|
||
def test_for_dict_str(): | ||
dict_str: dict[str, str] = {"a":"b", "c":"d"} | ||
key: str | ||
s1: str = "" | ||
s2: str = "" | ||
|
||
for key in dict_str: | ||
print(key) | ||
s1 += key | ||
s2 += dict_str[key] | ||
|
||
assert (s1 == "ac" or s1 == "ca") | ||
assert ((s1 == "ac" and s2 == "bd") or (s1 == "ca" and s2 == "db")) | ||
|
||
def test_for_set_int(): | ||
set_int: set[i32] = {1, 2, 3} | ||
el: i32 | ||
s: i32 = 0 | ||
|
||
for el in set_int: | ||
print(el) | ||
s += el | ||
|
||
assert s == 6 | ||
|
||
def test_for_set_str(): | ||
set_str: set[str] = {'a', 'b'} | ||
el: str | ||
s: str = "" | ||
|
||
for el in set_str: | ||
print(el) | ||
s += el | ||
|
||
assert (s == "ab" or s == "ba") | ||
|
||
def test_nested(): | ||
graph: dict[i32, set[i32]] = {1: {2, 3}} | ||
el: i32 | ||
s: i32 = 0 | ||
for el in graph[1]: | ||
print(el) | ||
s += el | ||
|
||
assert s == 5 | ||
|
||
|
||
test_for_dict_int() | ||
test_for_set_int() | ||
test_for_dict_str() | ||
test_for_set_str() | ||
test_nested() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
def test_clear(): | ||
a: dict[i32, i32] = {1:1, 2:2} | ||
|
||
a.clear() | ||
a[3] = 3 | ||
|
||
assert len(a) == 1 | ||
assert 3 in a | ||
|
||
b: dict[str, str] = {'a':'a', 'b':'b'} | ||
|
||
b.clear() | ||
b['c'] = 'c' | ||
|
||
assert len(b) == 1 | ||
assert 'c' in b | ||
|
||
test_clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
def test_int_dict(): | ||
a: dict[i32, i32] = {1:2, 2:3, 3:4, 4:5} | ||
i: i32 | ||
assert (1 in a) | ||
assert (6 not in a) | ||
i = 4 | ||
assert (i in a) | ||
|
||
def test_str_dict(): | ||
a: dict[str, str] = {'a':'1', 'b':'2', 'c':'3'} | ||
i: str | ||
assert ('a' in a) | ||
assert ('d' not in a) | ||
i = 'c' | ||
assert (i in a) | ||
|
||
def test_int_set(): | ||
a: set[i32] = {1, 2, 3, 4} | ||
i: i32 | ||
assert (1 in a) | ||
assert (6 not in a) | ||
i = 4 | ||
assert (i in a) | ||
|
||
def test_str_set(): | ||
a: set[str] = {'a', 'b', 'c', 'e', 'f'} | ||
i: str | ||
assert ('a' in a) | ||
# assert ('d' not in a) | ||
i = 'c' | ||
assert (i in a) | ||
|
||
test_int_dict() | ||
test_str_dict() | ||
test_int_set() | ||
test_str_set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
def test_clear(): | ||
a: set[i32] = {1, 2} | ||
|
||
a.clear() | ||
a.add(3) | ||
|
||
assert len(a) == 1 | ||
a.remove(3) | ||
assert len(a) == 0 | ||
|
||
b: set[str] = {'a', 'b'} | ||
|
||
b.clear() | ||
b.add('c') | ||
|
||
assert len(b) == 1 | ||
b.remove('c') | ||
assert len(b) == 0 | ||
|
||
|
||
test_clear() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
def set_pop_str(): | ||
s: set[str] = {'a', 'b', 'c'} | ||
|
||
assert s.pop() in {'a', 'b', 'c'} | ||
assert len(s) == 2 | ||
assert s.pop() in {'a', 'b', 'c'} | ||
assert s.pop() in {'a', 'b', 'c'} | ||
assert len(s) == 0 | ||
|
||
s.add('d') | ||
assert s.pop() == 'd' | ||
|
||
def set_pop_int(): | ||
s: set[i32] = {1, 2, 3} | ||
|
||
assert s.pop() in {1, 2, 3} | ||
assert len(s) == 2 | ||
assert s.pop() in {1, 2, 3} | ||
assert s.pop() in {1, 2, 3} | ||
assert len(s) == 0 | ||
|
||
s.add(4) | ||
assert s.pop() == 4 | ||
|
||
set_pop_str() | ||
set_pop_int() |
Oops, something went wrong.