diff --git a/kiwi.lua b/kiwi.lua index e7dc66f..a37b75c 100644 --- a/kiwi.lua +++ b/kiwi.lua @@ -445,7 +445,7 @@ do ---@return string ---@nodiscard function Var_cls:name() - return ffi_string(self.name_) + return self.name_ ~= nil and ffi_string(self.name_) or "" end --- Get the current value of the variable. diff --git a/spec/constraint_spec.lua b/spec/constraint_spec.lua index 6b9f7a1..ce3cd2b 100644 --- a/spec/constraint_spec.lua +++ b/spec/constraint_spec.lua @@ -84,18 +84,12 @@ describe("Constraint", function() local v2 = kiwi.Var("bar") local rhs = kiwi.Expression(3, 5 * v2, 3 * v) local c = kiwi.Constraint(lhs, rhs) + assert.True(c:violated()) + v:set(9) + v2:set(-4) + assert.False(c:violated()) - local e = c:expression() - local t = e:terms() - assert.equal(2, #t) - if t[1].var ~= v then - t[1], t[2] = t[2], t[1] - end - assert.equal(v, t[1].var) - assert.equal(-2.0, t[1].coefficient) - assert.equal(v2, t[2].var) - assert.equal(-5.0, t[2].coefficient) - assert.equal(-2.0, e.constant) + assert.equal(-2.0, c:expression().constant) end) end)