@@ -3,6 +3,7 @@ module TestVariable
33using Test
44
55import MutableArithmetics as MA
6+ import StarAlgebras as SA
67
78using MultivariatePolynomials
89const MP = MultivariatePolynomials
@@ -36,34 +37,36 @@ function test_variable_macro_with_Poly(var)
3637 @test_throws ErrorException @variable (m, p3[2 : 3 ] >= 0 , Poly (X))
3738end
3839
40+ function _algebra_element_type (B, mono)
41+ M = MP. monomial_type (mono)
42+ C = JuMP. VariableRef
43+ return SA. AlgebraElement{
44+ MB. Algebra{MB. SubBasis{B,M,MP. monomial_vector_type (M)},B,M},
45+ C,
46+ Vector{C},
47+ }
48+ end
49+
3950function _test_variable (
4051 m,
4152 p,
4253 monos,
4354 binary = false ,
4455 integer = false ,
45- vars = true ,
4656 use_y = true ,
57+ B = MB. Monomial,
4758)
48- PT = polynomial_type (
49- use_y ? first (monos) : first (variables (first (monos))),
50- vars ? JuMP. VariableRef : JuMP. AffExpr,
59+ @test isa (
60+ p,
61+ _algebra_element_type (
62+ B,
63+ use_y ? first (monos) : first (variables (first (monos))),
64+ ),
5165 )
52- @test isa (p, PT)
53- @test monomials (p) == monomial_vector (monos)
54- if vars
55- @test all (α -> JuMP. is_binary (α) == binary, coefficients (p))
56- @test all (α -> JuMP. is_integer (α) == integer, coefficients (p))
57- else
58- @test all (
59- α -> JuMP. is_binary (first (keys (α. terms))) == binary,
60- coefficients (p),
61- )
62- @test all (
63- α -> JuMP. is_integer (first (keys (α. terms))) == integer,
64- coefficients (p),
65- )
66- end
66+ @test SA. basis (p). monomials == monomial_vector (monos)
67+ coeffs = SA. coeffs (p, MB. explicit_basis (p))
68+ @test all (α -> JuMP. is_binary (α) == binary, coeffs)
69+ @test all (α -> JuMP. is_integer (α) == integer, coeffs)
6770end
6871
6972function test_MonomialBasis (var)
@@ -72,7 +75,7 @@ function test_MonomialBasis(var)
7275 X = [1 , y, x^ 2 , x, y^ 2 ]
7376 m = Model ()
7477 @variable m p1[1 : 3 ] Poly (X)
75- PT = polynomial_type ( x * y, JuMP . VariableRef )
78+ PT = _algebra_element_type (MB . Monomial, x * y)
7679 @test isa (p1, Vector{PT})
7780 _test_variable (m, p1[1 ], X)
7881 @variable (m, p2, Poly (X), integer = true )
@@ -102,7 +105,7 @@ function test_ScaledMonomialBasis(var)
102105 false ,
103106 true ,
104107 false ,
105- false ,
108+ MB . ScaledMonomial ,
106109 )
107110end
108111
0 commit comments