Skip to content

Commit

Permalink
changed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Apr 27, 2020
1 parent 2f346a9 commit 8bd8b21
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions test/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
@test out[1,0] == 3
@test out[1,1] == 4

dup = SG.unaryop(:DUP_TEST, a->a * 2)
dup = SG.unaryop(a->a * 2, name=:DUP_TEST)
A = SG.matrix_from_lists([0,0,1,1], [0,1,0,1], Int64[1,2,3,4])
out = SG.apply(A, unaryop = dup)
@test out.type == INT64
Expand Down Expand Up @@ -335,7 +335,7 @@
@test A[1,0] == 3
@test A[1,1] == 4

dup = SG.unaryop(:DUP_TEST, a->a * 2)
dup = SG.unaryop(a->a * 2)
A = SG.matrix_from_lists([0,0,1,1], [0,1,0,1], Int64[1,2,3,4])
SG.apply!(A, unaryop = dup)
@test A.type == INT64
Expand Down
61 changes: 31 additions & 30 deletions test/operator.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
valid_types = [Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32,Int64,UInt64,Float32,Float64]
count(d) = sum([length(d[k].impl) for k in keys(d)])
all_op(d) = filter(x->x != Symbol(split(string(d), ".")[end]), names(d, all = true))
count(d) = sum(map(x->length(getproperty(d, x).impl), all_op(d)))

@testset "Unary Operations" begin

# built-in unary ops
@test length(keys(Unaryop)) == 6
@test length(all_op(Unaryop)) == 6
@test count(Unaryop) == 66


SG.unaryop(:NO_TYPE, a->a)
@test haskey(Unaryop, :NO_TYPE)
SG.unaryop(a->a, name = :NO_TYPE)
@test hasproperty(Unaryop, :NO_TYPE)
uop_no_type = Unaryop.NO_TYPE
@test isempty(uop_no_type.impl)

# same unaryop
for type in valid_types
t = xtype = SG.j2gtype(type)
SG.unaryop(:SAME_TYPE, a->a, xtype = t, ztype = t)
SG.unaryop(a->a, xtype = t, ztype = t, name = :SAME_TYPE)
uop_type = Unaryop.SAME_TYPE
tmp = SG._get(uop_type, t, t)
@test isa(tmp, SG.GrB_UnaryOp)
Expand All @@ -29,8 +30,8 @@ count(d) = sum([length(d[k].impl) for k in keys(d)])
for type in valid_types
t = xtype = SG.j2gtype(type)
name = Symbol(:TYPE_, string(type))
SG.unaryop(name, a->a, xtype = t, ztype = t)
uop = Unaryop[name]
SG.unaryop(a->a, xtype = t, ztype = t, name = name)
uop = getproperty(Unaryop, name)
tmp = SG._get(uop, t, t)
@test isa(tmp, SG.GrB_UnaryOp)
@test tmp.xtype == t
Expand All @@ -43,19 +44,19 @@ end
@testset "Binary Operations" begin

# built-in binary ops
@test length(keys(Binaryop)) == 17 + 6
@test length(all_op(Binaryop)) == 17 + 6
@test count(Binaryop) == 253


SG.binaryop(:NO_TYPE, (a, b)->a)
@test haskey(Binaryop, :NO_TYPE)
SG.binaryop((a, b)->a, name = :NO_TYPE)
@test hasproperty(Binaryop, :NO_TYPE)
bop_no_type = Binaryop.NO_TYPE
@test isempty(bop_no_type.impl)

# same binary op
for type in valid_types
t = xtype = SG.j2gtype(type)
SG.binaryop(:SAME_TYPE, (a, b)->a + b, xtype = t, ytype = t, ztype = t)
t = SG.j2gtype(type)
SG.binaryop((a, b)->a+b; xtype = t, ytype = t, ztype = t, name = :SAME_TYPE)
bop_type = Binaryop.SAME_TYPE
tmp = SG._get(bop_type, t, t, t)
@test isa(tmp, SG.GrB_BinaryOp)
Expand All @@ -66,10 +67,10 @@ end

# different binary ops
for type in valid_types
t = xtype = SG.j2gtype(type)
t = SG.j2gtype(type)
name = Symbol(:TYPE_, string(type))
SG.binaryop(name, (a, b)->a + b, xtype = t, ytype = t, ztype = t)
bop = Binaryop[name]
SG.binaryop((a, b)->a+b, xtype = t, ytype = t, ztype = t, name = name)
bop = getproperty(Binaryop, name)
tmp = SG._get(bop, t, t, t)
@test isa(tmp, SG.GrB_BinaryOp)
@test tmp.xtype == t
Expand All @@ -89,26 +90,26 @@ end

bop = Binaryop.PLUS

mon_plus = SG.monoid(:MON_PLUS, bop, Int64(0))
mon_plus = SG.monoid(bop, Int64(0), name = :MON_PLUS)
@test length(mon_plus.impl) == 1
@test haskey(Monoids, :MON_PLUS)
@test hasproperty(Monoids, :MON_PLUS)
@test mon_plus.impl[1].domain == INT64

mon_plus_clone = SG.monoid(:MON_PLUS, bop, Int8(0))
mon_plus_clone = SG.monoid(bop, Int8(0), name = :MON_PLUS)
@test length(mon_plus_clone.impl) == 2
@test mon_plus.impl[2].domain == INT8
@test mon_plus_clone === mon_plus
@test haskey(Monoids, :MON_PLUS)
@test hasproperty(Monoids, :MON_PLUS)

mon_plus_fp64 = SG.monoid(:MON_PLUS, bop, Float64(0))
mon_plus_fp64 = SG.monoid(bop, Float64(0), name=:MON_PLUS)
@test length(mon_plus_fp64.impl) == 3
@test mon_plus_fp64.impl[3].domain == FP64
@test mon_plus_fp64 === mon_plus
@test haskey(Monoids, :MON_PLUS)
@test hasproperty(Monoids, :MON_PLUS)

mon2 = SG.monoid(:DUPLICATE, bop, Int8(0))
mon2 = SG.monoid(bop, Int8(0), name=:DUPLICATE)
@test length(mon2.impl) == 1
mon_duplicate = SG.monoid(:DUPLICATE, bop, Int8(0))
mon_duplicate = SG.monoid(bop, Int8(0), name=:DUPLICATE)
@test length(mon2.impl) == 1
@test length(mon_duplicate.impl) == 1
@test mon2 === mon_duplicate
Expand All @@ -117,7 +118,7 @@ end
# get_monoid
for t in valid_types
type = SG.j2gtype(t)
mon = SG.monoid(:TEST_MONOID, bop, t(0))
mon = SG.monoid(bop, t(0), name=:TEST_MONOID)
@test SG._get(mon, type).domain == type
end

Expand All @@ -131,8 +132,8 @@ end
# monoid and binary op built in
mon = Monoids.PLUS
bop = Binaryop.PLUS
sem = SG.semiring(:SEM_BUILTIN, mon, bop)
@test haskey(Semirings, :SEM_BUILTIN)
sem = SG.semiring(mon, bop, name=:SEM_BUILTIN)
@test hasproperty(Semirings, :SEM_BUILTIN)
@test isa(sem, SG.Semiring)
@test sem.monoid == mon
@test sem.binaryop == bop
Expand All @@ -144,10 +145,10 @@ end
@test length(Semirings.SEM_BUILTIN.impl) == 1

# user defined
bop = SG.binaryop(:BOP_USER, (a,b)->a+b)
mon = SG.monoid(:MON_USER, bop, Int64(0))
mon = SG.monoid(:MON_USER, bop, Int8(0))
sem1 = SG.semiring(:SEM_USER, mon, bop)
bop = SG.binaryop((a, b)->a + b, name=:BOP_USER)
mon = SG.monoid(bop, Int64(0), name=:MON_USER)
mon = SG.monoid(bop, Int8(0), name=:MON_USER)
sem1 = SG.semiring(mon, bop, name=:SEM_USER)
@test isa(sem1, SG.Semiring)
sem_int64 = SG._get(sem1, INT64, INT64, INT64)
@test sem_int64.xtype == INT64
Expand Down
2 changes: 1 addition & 1 deletion test/vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
@test out[2] == 3
@test out[3] == 4

dup = SG.unaryop(:DUP_TEST, a->a * 2)
dup = SG.unaryop(a->a * 2)
v = SG.from_vector(Int64[1,2,3,4])
out = SG.apply(v, unaryop = dup)
@test out.type == INT64
Expand Down

0 comments on commit 8bd8b21

Please sign in to comment.