Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
D
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomlogo committed Oct 24, 2021
1 parent 3f3ee16 commit 7a64cb7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dinoux/dparser.py → dinoux/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
The parser module for dinoux
"""
from dinoux.dtoken import *
from dinoux.token import *
import re

DIGITS = "0123456789."
Expand Down
2 changes: 1 addition & 1 deletion dinoux/ptstack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dinoux.dstack as dstack
import dinoux.stack as dstack

s = dstack.Stack()

Expand Down
68 changes: 34 additions & 34 deletions dinoux/ptutils.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
import dinoux.dutils as dutils
import dinoux.utils as utils


def test_depth():
assert dutils.depth(4) == 0
assert dutils.depth(21) == 0
assert dutils.depth([]) == 1
assert dutils.depth([2]) == 1
assert dutils.depth([2, []]) == 2
assert dutils.depth([[]]) == 2
assert dutils.depth([[], [3, [5]]]) == 3
assert utils.depth(4) == 0
assert utils.depth(21) == 0
assert utils.depth([]) == 1
assert utils.depth([2]) == 1
assert utils.depth([2, []]) == 2
assert utils.depth([[]]) == 2
assert utils.depth([[], [3, [5]]]) == 3

def test_split():
assert dutils.split([1, 2, 3, 4, 5, 6], 3) == [[1, 2, 3], [4, 5, 6]]
assert utils.split([1, 2, 3, 4, 5, 6], 3) == [[1, 2, 3], [4, 5, 6]]

def test_rotate_first():
assert dutils.rotate_first([1, 2, 3, 4]) == [4, 1, 2, 3]
assert dutils.rotate_first([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[4, 8], [1, 5], [2, 6], [3, 7]]
assert utils.rotate_first([1, 2, 3, 4]) == [4, 1, 2, 3]
assert utils.rotate_first([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[4, 8], [1, 5], [2, 6], [3, 7]]

def test_rotate():
assert dutils.rotate([1, 2, 3, 4]) == [1, 2, 3, 4]
assert dutils.rotate([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[5, 1], [6, 2], [7, 3], [8, 4]]
assert utils.rotate([1, 2, 3, 4]) == [1, 2, 3, 4]
assert utils.rotate([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[5, 1], [6, 2], [7, 3], [8, 4]]

def test_reverse_first():
assert dutils.reverse_first([1, 2, 3, 4]) == [4, 3, 2, 1]
assert dutils.reverse_first([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[4, 8], [3, 7], [2, 6], [1, 5]]
assert utils.reverse_first([1, 2, 3, 4]) == [4, 3, 2, 1]
assert utils.reverse_first([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[4, 8], [3, 7], [2, 6], [1, 5]]

def test_reverse():
assert dutils.reverse([1, 2, 3, 4]) == [4, 3, 2, 1]
assert dutils.reverse([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[5, 1], [6, 2], [7, 3], [8, 4]]
assert utils.reverse([1, 2, 3, 4]) == [4, 3, 2, 1]
assert utils.reverse([[1, 5], [2, 6], [3, 7], [4, 8]]) == [[5, 1], [6, 2], [7, 3], [8, 4]]

def test_reduce_first():
assert dutils.reduce_first(lambda x,y: x+y, [1, 2, 3, 4]) == 10
assert dutils.reduce_first(lambda x,y: x+y, [[1, 5], [2, 6], [3, 7], [4, 8]]) == [1, 5, 2, 6, 3, 7, 4, 8]
assert utils.reduce_first(lambda x,y: x+y, [1, 2, 3, 4]) == 10
assert utils.reduce_first(lambda x,y: x+y, [[1, 5], [2, 6], [3, 7], [4, 8]]) == [1, 5, 2, 6, 3, 7, 4, 8]

def test_reduce():
assert dutils.reduce(lambda x,y: x+y, [1, 2, 3, 4]) == 10
assert dutils.reduce(lambda x,y: x+y, [[1, 5], [2, 6], [3, 7], [4, 8]]) == [6, 8, 10, 12]
assert utils.reduce(lambda x,y: x+y, [1, 2, 3, 4]) == 10
assert utils.reduce(lambda x,y: x+y, [[1, 5], [2, 6], [3, 7], [4, 8]]) == [6, 8, 10, 12]

def test_transpose():
assert dutils.transpose([[1, 2], [3, 4]]) == [[1, 3], [2, 4]]
assert utils.transpose([[1, 2], [3, 4]]) == [[1, 3], [2, 4]]

def test_vectorise1():
assert dutils.vectorise1(lambda x: x+1, [1, 2, 3, 4, 5]) == [2, 3, 4, 5, 6]
assert dutils.vectorise1(lambda x: x*2, [1, 2, [4, 5, [3]]]) == [2, 4, [8, 10, [6]]]
assert utils.vectorise1(lambda x: x+1, [1, 2, 3, 4, 5]) == [2, 3, 4, 5, 6]
assert utils.vectorise1(lambda x: x*2, [1, 2, [4, 5, [3]]]) == [2, 4, [8, 10, [6]]]

def test_vectorise2():
assert dutils.vectorise2(lambda x,y: x+y, [1, [2, 3], [4]], [[[10, 20], [30], 40, 50], 60]) == [[[11, 21], [32, 3], [44], 50], [61, [62, 63], [64]]]
assert dutils.vectorise2(lambda x,y: x*y, [1, 2, 3, [4, 5]], [1, 2, 3]) == [[1, 2, 3], [2, 4, 6], [3, 6, 9], [4, 10, 0]]
assert utils.vectorise2(lambda x,y: x+y, [1, [2, 3], [4]], [[[10, 20], [30], 40, 50], 60]) == [[[11, 21], [32, 3], [44], 50], [61, [62, 63], [64]]]
assert utils.vectorise2(lambda x,y: x*y, [1, 2, 3, [4, 5]], [1, 2, 3]) == [[1, 2, 3], [2, 4, 6], [3, 6, 9], [4, 10, 0]]

def test_matmul():
assert dutils.matmul([[2, 3, 5], [6, 5, 2], [0, 4, 6]], [[2, 3, 1], [3, 1, 6], [1, 4, 8]]) == [[18, 29, 60], [29, 31, 52], [18, 28, 72]]
assert dutils.matmul([[2, 3, 1], [3, 1, 6], [1, 4, 8]], [[2, 3, 5], [6, 5, 2], [0, 4, 6]]) == [[22, 25, 22], [12, 38, 53], [26, 55, 61]]
assert utils.matmul([[2, 3, 5], [6, 5, 2], [0, 4, 6]], [[2, 3, 1], [3, 1, 6], [1, 4, 8]]) == [[18, 29, 60], [29, 31, 52], [18, 28, 72]]
assert utils.matmul([[2, 3, 1], [3, 1, 6], [1, 4, 8]], [[2, 3, 5], [6, 5, 2], [0, 4, 6]]) == [[22, 25, 22], [12, 38, 53], [26, 55, 61]]

def test_reshape():
assert dutils.reshape([3, 3], [1, 2, 3]) == [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
assert dutils.reshape([4, 1, 2, 3], [1, 3, 4, 2]) == [[[[1, 3, 4], [2, 1, 3]]], [[[4, 2, 1], [3, 4, 2]]], [[[1, 3, 4], [2, 1, 3]]], [[[4, 2, 1], [3, 4, 2]]]]
assert utils.reshape([3, 3], [1, 2, 3]) == [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
assert utils.reshape([4, 1, 2, 3], [1, 3, 4, 2]) == [[[[1, 3, 4], [2, 1, 3]]], [[[4, 2, 1], [3, 4, 2]]], [[[1, 3, 4], [2, 1, 3]]], [[[4, 2, 1], [3, 4, 2]]]]

def test_flatten():
assert dutils.flatten([1, [2, 3]]) == [1, 2, 3]
assert dutils.flatten([1, [2, 3, [4, 5]]]) == [1, 2, 3, 4, 5]
assert utils.flatten([1, [2, 3]]) == [1, 2, 3]
assert utils.flatten([1, [2, 3, [4, 5]]]) == [1, 2, 3, 4, 5]

def test_astr():
assert dutils.astr([[1, 2], [3, 4]]) == '1 2\n3 4'
assert dutils.astr([1, 2, [3, 4]]) == '1 2 [3, 4]'
assert utils.astr([[1, 2], [3, 4]]) == '1 2\n3 4'
assert utils.astr([1, 2, [3, 4]]) == '1 2 [3, 4]'
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7a64cb7

Please sign in to comment.