Skip to content

Commit

Permalink
Equality of FunctionTerms (#205)
Browse files Browse the repository at this point in the history
* confirm failing test for #204

* equality for FuncionTerm check function and original expression

* test that adding two non-equal FunctionTerms works correctly
  • Loading branch information
kleinschmidt authored Jan 5, 2021
1 parent e6b5f23 commit 6c757d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/terms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ FunctionTerm(forig::Fo, fanon::Fa, names::NTuple{N,Symbol},
FunctionTerm{Fo, Fa, names}(forig, fanon, exorig, args_parsed)
width(::FunctionTerm) = 1

Base.:(==)(a::FunctionTerm, b::FunctionTerm) = a.forig == b.forig && a.exorig == b.exorig

"""
InteractionTerm{Ts} <: AbstractTerm
Expand Down
12 changes: 12 additions & 0 deletions test/terms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ StatsModels.apply_schema(mt::MultiTerm, sch::StatsModels.Schema, Mod::Type) =
@test ab+bc == abc
end

@testset "uniqueness of FunctionTerms" begin
f1 = @formula(y ~ lag(x,1) + lag(x,1))
f2 = @formula(y ~ lag(x,1))
f3 = @formula(y ~ lag(x,1) + lag(x,2))

@test f1.rhs == f2.rhs
@test f1.rhs != f3.rhs

## addition of two identical function terms
@test f2.rhs + f2.rhs == f2.rhs
end

@testset "expand nested tuples of terms during apply_schema" begin
sch = schema((a=rand(10), b=rand(10), c=rand(10)))

Expand Down

0 comments on commit 6c757d4

Please sign in to comment.