<commit_before>-- Copyright (c) 2009-2012 Incremental IP Limited
-- see LICENSE for license information

local constraint = require("rima.mp.constraint")

local core = require("rima.core")
local number_t = require("rima.types.number_t")
local interface = require("rima.interface")


------------------------------------------------------------------------------

return function(T)
  local E = interface.eval
  local R = interface.R

  local a, b, c, d = R"a, b, c, d"
  local S = { a = number_t.free(), b = 3, c = number_t.free(), d = 5 }
  local C
  T:expect_ok(function() C = constraint:new(a * b + c * d, "<=", 3) end)
  T:check_equal(C, "a*b + c*d <= 3")
  T:check_equal(E(C, S), "3*a + 5*c <= 3")

  local lower, upper, lhs, _
  T:expect_ok(function() lower, upper, _, lhs = C:characterise(S) end)
  T:check_equal(upper, 3)
  T:check_equal(lower, -math.huge)
  T:check_equal(lhs.a.coeff, 3)
  T:check_equal(lhs.c.coeff, 5)
end


------------------------------------------------------------------------------
<commit_msg>Tidied constraint tests<commit_after>-- Copyright (c) 2009-2012 Incremental IP Limited
-- see LICENSE for license information

local number_t = require("rima.types.number_t")
local interface = require("rima.interface")


------------------------------------------------------------------------------

return function(T)
  local E = interface.eval
  local R = interface.R

  local a, b, c, d = R"a, b, c, d"
  local S = { a = number_t.free(), b = 3, c = number_t.free(), d = 5 }
  local C
  T:expect_ok(function() C = interface.mp.constraint(a * b + c * d, "<=", 3) end)
  T:check_equal(C, "a*b + c*d <= 3")
  T:check_equal(E(C, S), "3*a + 5*c <= 3")

  local lower, upper, lhs, _
  T:expect_ok(function() lower, upper, _, lhs = C:characterise(S) end)
  T:check_equal(upper, 3)
  T:check_equal(lower, -math.huge)
  T:check_equal(lhs.a.coeff, 3)
  T:check_equal(lhs.c.coeff, 5)
end


------------------------------------------------------------------------------

{'fraction_non_alphanumeric': 0.29894313034725717, 'fraction_numerical': 0.018117765475591345, 'mean_word_length': 2.025875190258752, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4870139', 'n_tokens_mistral': 718, 'n_tokens_neox': 675, 'n_words': 174}