Skip to content

Commit 6c757d4

Browse files
authored
Equality of FunctionTerms (#205)
* confirm failing test for #204 * equality for FuncionTerm check function and original expression * test that adding two non-equal FunctionTerms works correctly
1 parent e6b5f23 commit 6c757d4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/terms.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ FunctionTerm(forig::Fo, fanon::Fa, names::NTuple{N,Symbol},
127127
FunctionTerm{Fo, Fa, names}(forig, fanon, exorig, args_parsed)
128128
width(::FunctionTerm) = 1
129129

130+
Base.:(==)(a::FunctionTerm, b::FunctionTerm) = a.forig == b.forig && a.exorig == b.exorig
131+
130132
"""
131133
InteractionTerm{Ts} <: AbstractTerm
132134

test/terms.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ StatsModels.apply_schema(mt::MultiTerm, sch::StatsModels.Schema, Mod::Type) =
8686
@test ab+bc == abc
8787
end
8888

89+
@testset "uniqueness of FunctionTerms" begin
90+
f1 = @formula(y ~ lag(x,1) + lag(x,1))
91+
f2 = @formula(y ~ lag(x,1))
92+
f3 = @formula(y ~ lag(x,1) + lag(x,2))
93+
94+
@test f1.rhs == f2.rhs
95+
@test f1.rhs != f3.rhs
96+
97+
## addition of two identical function terms
98+
@test f2.rhs + f2.rhs == f2.rhs
99+
end
100+
89101
@testset "expand nested tuples of terms during apply_schema" begin
90102
sch = schema((a=rand(10), b=rand(10), c=rand(10)))
91103

0 commit comments

Comments
 (0)