Skip to content

Commit

Permalink
Add preliminary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Nov 5, 2024
1 parent 94b188a commit f2d4633
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Sparse/Row.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ function Base.empty!(A::SRow)
return A
end

function Base.empty(A::SRow)
return sparse_row(base_ring(A))
end

function zero(A::SRow)
return empty(A)
end

function swap!(A::SRow, B::SRow)
A.pos, B.pos = B.pos, A.pos
A.values, B.values = B.values, A.values
Expand Down
29 changes: 29 additions & 0 deletions test/Sparse/Row.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,33 @@
B = sparse_row(F,[1],[y])
C = add_scaled_row(A,B,F(1))
@test C == A+B

# mutating arithmetic
randcoeff() = rand(-20:20)
Main.equality(A::SRow, B::SRow) = A == B
for _ in 1:10
maxind_A = rand(0:10)
inds_A = Hecke.Random.randsubseq(1:maxind_A, rand())
vals_A = [rand(ZZ, -10:10) for _ in 1:length(inds_A)]
A = sparse_row(FlintZZ, inds_A, vals_A)

maxind_B = rand(0:10)
inds_B = Hecke.Random.randsubseq(1:maxind_B, rand())
vals_B = [rand(ZZ, -10:10) for _ in 1:length(inds_B)]
B = sparse_row(FlintZZ, inds_B, vals_B)

test_mutating_op_like_zero(zero, zero!, A)

test_mutating_op_like_neg(-, neg!, A)

test_mutating_op_like_add(+, add!, A, B)
test_mutating_op_like_add(-, sub!, A, B)
# test_mutating_op_like_add(*, mul!, A, randcoeff())
# test_mutating_op_like_add(*, mul!, randcoeff(), A)
# test_mutating_op_like_add(*, mul!, A, ZZ(randcoeff()))
# test_mutating_op_like_add(*, mul!, ZZ(randcoeff()), A)

# test_mutating_op_like_addmul((a, b, c) -> a + b*c, addmul!, A, B, randcoeff())
# test_mutating_op_like_addmul((a, b, c) -> a - b*c, submul!, A, B, randcoeff())
end
end

0 comments on commit f2d4633

Please sign in to comment.