diff --git a/src/terms.jl b/src/terms.jl index be86b7b0..56189b7c 100644 --- a/src/terms.jl +++ b/src/terms.jl @@ -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 diff --git a/test/terms.jl b/test/terms.jl index fdbde6f5..ac414443 100644 --- a/test/terms.jl +++ b/test/terms.jl @@ -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)))