<commit_before>import math
import unittest
from gpkit import Monomial, Posynomial


class t_Monomial(unittest.TestCase):

    def setUp(self):
        pass

    def test_init(self):
        m = Monomial({'x':2, 'y':-1}, 5)
        m2 = Monomial({'x': 2, 'y': -1}, 5)
        self.assertEqual(m.var_locs, {'x':[0], 'y':[0]})
        self.assertEqual(m.exp, {'x': 2, 'y': -1})
        self.assertEqual(m.c, 5)
        self.assertEqual(m, m2)

        # default c and a
        m = Monomial('x')
        self.assertEqual(m.var_locs, {'x': [0]})
        self.assertEqual(m.exp, {'x': 1})
        self.assertEqual(m.c, 1)

        # single (string) var with non-default c
        m = Monomial('tau', .1)
        self.assertEqual(m.var_locs, {'tau': [0]})
        self.assertEqual(m.exp, {'tau': 1})
        self.assertEqual(m.c, .1)

        # variable names not compatible with python namespaces
        crazy_varstr = 'what the !!!/$\**?'
        m = Monomial({'x': 1, crazy_varstr: .5}, 25)
        self.assertTrue(crazy_varstr in m.exp)

        # non-positive c raises
        self.assertRaises(ValueError, Monomial, 'x', -2)
        self.assertRaises(ValueError, Monomial, {'x': 2}, -1.)
        self.assertRaises(ValueError, Monomial, 'x', 0)
        self.assertRaises(ValueError, Monomial, 'x', 0.0)

        # can create nameless Monomials
        x1 = Monomial()
        x2 = Monomial()
        V = Monomial('V')
        vel = Monomial('V')
        self.assertNotEqual(x1, x2)
        self.assertEqual(V, vel)

    def test_repr(self):
        m = Monomial({'x':2, 'y':-1}, 5)
        self.assertEqual(type(m.__repr__()), str)
        self.assertEqual(Monomial('x').__repr__(), 'gpkit.Monomial(x)')

    def test_latex(self):
        m = Monomial({'x':2, 'y':-1}, 5)._latex()
        self.assertEqual(type(m), str)
        self.assertEqual(Monomial('x', 5)._latex(), '5x')

    def test_eq_ne(self):
        # simple one
        x = Monomial('x')
        y = Monomial('y')
        self.assertNotEqual(x, y)
        self.assertNotEqual(x, y)

        xx = Monomial('x')
        self.assertEqual(x, xx)
        self.assertFalse(x != xx)

        self.assertEqual(x, x)
        self.assertFalse(x != x)

        # scalar fails on type comparison even though c matches
        # NOTE(bqpd): not anymore!
        x = Monomial({}, 1)
        y = 1
        self.assertEqual(x, y)
        self.assertEqual(x, Monomial({}))

        # several vars
        m1 = Monomial({'a':3, 'b':2, 'c':1}, 5)<commit_msg>fix duplicate line in test<commit_after>import math
import unittest
from gpkit import Monomial, Posynomial


class t_Monomial(unittest.TestCase):

    def setUp(self):
        pass

    def test_init(self):
        m = Monomial({'x':2, 'y':-1}, 5)
        m2 = Monomial({'x': 2, 'y': -1}, 5)
        self.assertEqual(m.var_locs, {'x':[0], 'y':[0]})
        self.assertEqual(m.exp, {'x': 2, 'y': -1})
        self.assertEqual(m.c, 5)
        self.assertEqual(m, m2)

        # default c and a
        m = Monomial('x')
        self.assertEqual(m.var_locs, {'x': [0]})
        self.assertEqual(m.exp, {'x': 1})
        self.assertEqual(m.c, 1)

        # single (string) var with non-default c
        m = Monomial('tau', .1)
        self.assertEqual(m.var_locs, {'tau': [0]})
        self.assertEqual(m.exp, {'tau': 1})
        self.assertEqual(m.c, .1)

        # variable names not compatible with python namespaces
        crazy_varstr = 'what the !!!/$\**?'
        m = Monomial({'x': 1, crazy_varstr: .5}, 25)
        self.assertTrue(crazy_varstr in m.exp)

        # non-positive c raises
        self.assertRaises(ValueError, Monomial, 'x', -2)
        self.assertRaises(ValueError, Monomial, {'x': 2}, -1.)
        self.assertRaises(ValueError, Monomial, 'x', 0)
        self.assertRaises(ValueError, Monomial, 'x', 0.0)

        # can create nameless Monomials
        x1 = Monomial()
        x2 = Monomial()
        V = Monomial('V')
        vel = Monomial('V')
        self.assertNotEqual(x1, x2)
        self.assertEqual(V, vel)

    def test_repr(self):
        m = Monomial({'x':2, 'y':-1}, 5)
        self.assertEqual(type(m.__repr__()), str)
        self.assertEqual(Monomial('x').__repr__(), 'gpkit.Monomial(x)')

    def test_latex(self):
        m = Monomial({'x':2, 'y':-1}, 5)._latex()
        self.assertEqual(type(m), str)
        self.assertEqual(Monomial('x', 5)._latex(), '5x')

    def test_eq_ne(self):
        # simple one
        x = Monomial('x')
        y = Monomial('y')
        self.assertNotEqual(x, y)
        self.assertFalse(x == y)

        xx = Monomial('x')
        self.assertEqual(x, xx)
        self.assertFalse(x != xx)

        self.assertEqual(x, x)
        self.assertFalse(x != x)

        # scalar fails on type comparison even though c matches
        # NOTE(bqpd): not anymore!
        x = Monomial({}, 1)
        y = 1
        self.assertEqual(x, y)
        self.assertEqual(x, Monomial({}))

        # several vars
        m1 = Monomial({'a':3, 'b':2, 'c':1}, 5)
{'fraction_non_alphanumeric': 0.16799521721801514, 'fraction_numerical': 0.019529693104822637, 'mean_word_length': 2.2173076923076924, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2065595', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1740, 'n_words': 393}