def test_variance_method_calculator(self):
     calculator = Calculator()
     random_generator = RandomGenerator()
     test_list = random_generator.rand_list(self, 0, 100, 5, 3)
     variance = calculator.variance(test_list)
     self.assertEqual(calculator.variance(test_list), variance)
     self.assertEqual(calculator.result, variance)
Пример #2
0
def generate_controlled_data():
    calc = Calculator()
    file_path = 'data/eq2/'
    generate_file_path(file_path)
    with open(file_path + 'datasetx1.arff', 'a') as filex1:
        with open(file_path + 'datasetx2.arff', 'a') as filex2:
            filex1.write('@relation eq_segundo_grau_x1\n\n')
            filex1.write('@attribute a NUMERIC\n')
            filex1.write('@attribute b NUMERIC\n')
            filex1.write('@attribute c NUMERIC\n')
            filex1.write('@attribute x1 NUMERIC\n\n')
            filex1.write('@data\n')
            filex2.write('@relation eq_segundo_grau_x2\n\n')
            filex2.write('@attribute a NUMERIC\n')
            filex2.write('@attribute b NUMERIC\n')
            filex2.write('@attribute c NUMERIC\n')
            filex2.write('@attribute x2 NUMERIC\n\n')
            filex2.write('@data\n')
            for i in range(-25, 25):
                for j in range(-25, 25):
                    for k in range(-25, 25):
                        if i is not 0:
                            a = i
                            b = j
                            c = k
                            xs = calc.resolve_eq(a, b, c)
                            if xs[0] is not "nr":
                                filex1.write(
                                    str(a) + ', ' + str(b) + ', ' + str(c) +
                                    ', ' + str(xs[0]) + '\n')
                                filex2.write(
                                    str(a) + ', ' + str(b) + ', ' + str(c) +
                                    ', ' + str(xs[1]) + '\n')
 def test_std_dev_method_calculator(self):
     calculator = Calculator()
     random_generator = RandomGenerator()
     test_list = random_generator.rand_list(self, 0, 100, 5, 3)
     std_dev = calculator.standard_dev(test_list)
     self.assertEqual(calculator.standard_dev(test_list), std_dev)
     self.assertEqual(calculator.result, std_dev)
Пример #4
0
class Main():
    def __init__(self):
        self.cal = Calculator()
        self.data_maps = DataMaps()
        self.translator = Translator()

    def calculateValue(self):
        print('done')

    def run(self):
        running = True
        while running:
            name = str.strip(str(input('Name? :')))
            self.cal.set_value(name)
            outexpr = self.cal.get_outter_expression()
            soul = self.cal.get_soul_urge()
            print('---------------')
            print(self.data_maps.get_vidic(outexpr))
            print('---------------')
            print(self.data_maps.get_behaviour(outexpr))
            print('---------------')
            print(self.data_maps.get_expressions(outexpr))
            print('---------------')
            print(self.data_maps.get_soul_urge(soul))
            print('---------------')

            ans = str.strip(str(input('Continue [y/n]?:')))

            if ans == 'n':
                running = False
                print('done')

            self.cal = Calculator()
Пример #5
0
class CalculatorTest(unittest.TestCase):
    """unitetestモジュールの簡単な実行例その1。"""
    @classmethod
    def setUpClass(cls):
        pass

    @classmethod
    def tearDownClass(cls):
        pass

    def setUp(self):
        self._calculator = Calculator()

    def tearDown(self):
        pass

    def test_add(self):
        self.assertEqual(self._calculator.add(1.5, 1.5), 3)

    def test_subtract(self):
        self.assertEqual(self._calculator.subtract(1.5, 1), 0.5)

    def test_multiply(self):
        self.assertEqual(self._calculator.multiply(1.5, 1.5), 2.25)

    def test_divide(self):
        self.assertEqual(self._calculator.divide(1.5, 0.3), 5)
Пример #6
0
def generate_data():
    calc = Calculator()
    with open('datasetx1.arff', 'a') as filex1:
        with open('datasetx2.arff', 'a') as filex2:
            filex1.write('@relation eq_segundo_grau_x1\n\n')
            filex1.write('@attribute a NUMERIC\n')
            filex1.write('@attribute b NUMERIC\n')
            filex1.write('@attribute c NUMERIC\n')
            filex1.write('@attribute x1 NUMERIC\n\n')
            filex1.write('@data\n')
            filex2.write('@relation eq_segundo_grau_x2\n\n')
            filex2.write('@attribute a NUMERIC\n')
            filex2.write('@attribute b NUMERIC\n')
            filex2.write('@attribute c NUMERIC\n')
            filex2.write('@attribute x2 NUMERIC\n\n')
            filex2.write('@data\n')
            for i in range(0, 1000000):
                a = 0
                while a is 0:
                    a = randint(-100, 100)
                b = randint(-100, 100)
                c = randint(-100, 100)
                xs = calc.resolve_eq(a, b, c)
                if xs[0] is not "nr":
                    filex1.write(
                        str(a) + ', ' + str(b) + ', ' + str(c) + ', ' +
                        str(xs[0]) + '\n')
                    filex2.write(
                        str(a) + ', ' + str(b) + ', ' + str(c) + ', ' +
                        str(xs[1]) + '\n')
Пример #7
0
 def returnPrice(self):
     bps= BasePriceList(self.baseprices).prices
     total= 0
     calculate= Calculator(bps)
     for product in self.cart:
         total += calculate.get_price(product)
     return '{total}\n'.format(total=total)
 def test_mode_method_calculator(self):
     calculator = Calculator()
     random_generator = RandomGenerator()
     test_list = random_generator.rand_list(self, 0, 100, 5, 3)
     values_mode = calculator.mode(test_list)
     self.assertEqual(calculator.mode(test_list), values_mode)
     self.assertEqual(calculator.result, values_mode)
     test_list.clear()
 def test_median_method_calculator(self):
     calculator = Calculator()
     random_generator = RandomGenerator()
     test_list = random_generator.rand_list(self, 0, 100, 5, 3)
     median = calculator.median(test_list)
     self.assertEqual(calculator.median(test_list), median)
     self.assertEqual(calculator.result, median)
     test_list.clear()
Пример #10
0
 def test_z_score_method_calculator(self):
     calculator = Calculator()
     random_generator = RandomGenerator()
     test_list = random_generator.rand_list(self, 0, 100, 5, 3)
     test_score = 10
     z_score = calculator.z_score(test_list, test_score)
     self.assertEqual(calculator.z_score(test_list, test_score), z_score)
     self.assertEqual(calculator.result, z_score)
 def test_should_return_name_of_the_second_hotel_because_its_cheaper(self):
     hotels = [
         Hotel('Wood', 10, 20, 20, 25, 1),
         Hotel('LakeWood', 8, 10, 20, 25, 1)
     ]
     calculator = Calculator(hotels)
     self.assertEqual(calculator.getCheappest(customerType, period),
                      'LakeWood')
 def test_should_return_name_of_the_cheapper_hotel_when_pass_two_hotels_with_same_price(
         self):
     hotels = [
         Hotel('LakeWood', 10, 20, 20, 25, 1),
         Hotel('Wood', 10, 20, 20, 25, 2)
     ]
     calculator = Calculator(hotels)
     self.assertEqual(calculator.getCheappest(customerType, period), 'Wood')
Пример #13
0
class CalculatorTestCase(unittest.TestCase):

    def setUp(self):
        self.cal = Calculator()

    def testAddition(self):
        result = self.cal.addition(0.001, 0.003)
        self.assertEqual(0.004, result)

    def testSubtraction(self):
        result = self.cal.subtraction(0.1, 0.001)
        self.assertEqual(0.099, result)

    def testMultiply(self):
        result = self.cal.multiply(0.001, 10)
        self.assertEquals(0.01, result)

    def testDivide(self):
        result = self.cal.divide(5, 1000)
        self.assertEquals(0.005, result)

    def testDivideError(self):
        self.assertRaises(ValueError, self.cal.divide, 10, 0)

    def testLogMyMore(self):
        result = self.cal.logMy(25, 5)
        self.assertEquals(2, result)

    def testLogMyLess(self):
        result = self.cal.logMy(0.125, 2)
        self.assertEquals(-3, result)

    def testLog(self):
        log1 = self.cal.logMath(0.221, 2.5)
        log2 = self.cal.logMy(0.221, 2.5)
        self.assertEquals(round(log1, 5), log2)

    def testLogMyErrorOne(self):
        self.assertRaises(ValueError, self.cal.logMy, 100, 0)

    def testLogMyErrorTwo(self):
        self.assertRaises(ZeroDivisionError, self.cal.logMy, 100, 1)

    def testLogMathMore(self):
        result = self.cal.logMath(25, 5)
        self.assertEquals(2, result)

    def testLogMathLess(self):
        result = self.cal.logMath(0.125, 2)
        self.assertEquals(-3, result)

    def testLogMathErrorOne(self):
        self.assertRaises(ValueError, self.cal.logMath, 100, 0)

    def testLogMathErrorTwo(self):
        self.assertRaises(ZeroDivisionError, self.cal.logMath, 100, 1)
Пример #14
0
 def test_eq2(self):
     c = Calculator()
     r1 = c.resolve_eq(3, 4, 1)
     r2 = c.resolve_eq(1, -1, -1)
     r3 = c.resolve_eq(9, -5, 0)
     r4 = c.resolve_eq(5, 0, -4)
     self.assertAlmostEqual(r1[0], [-0.3333333333333333, -1.0][0])
     self.assertAlmostEqual(r2[0], [1.618033988749895,
                                    -0.6180339887498949][0])
     self.assertAlmostEqual(r3[0], [0.5555555555555556, 0.0][0])
     self.assertAlmostEqual(r4[0], [0.894427190999916,
                                    -0.894427190999916][0])
Пример #15
0
def generate_logarithm_data():
    calc = Calculator()
    file_path = 'data/log/'
    generate_file_path(file_path)
    with open(file_path + 'datasetlog.arff', 'a') as filelog:
        filelog.write('@relation logaritmo\n\n')
        filelog.write('@attribute base NUMERIC\n')
        filelog.write('@attribute num NUMERIC\n')
        filelog.write('@attribute x NUMERIC\n\n')
        filelog.write('@data\n')
        for i in range(2, 64):
            for j in range(1, 1000):
                a = i
                b = j
                x = calc.resolve_log(a, b)
                filelog.write(str(a) + ', ' + str(b) + ', ' + str(x) + '\n')
class CalculatorTest(unittest.TestCase):

    def setUp(self):
        self.calc = Calculator()

    def test_calculate_iva(self):

        result = self.calc.get_iva(100) # 16
        result2 = self.calc.get_iva(200) # 32
        result3 = self.calc.get_iva(500)  # 80
        result4 = self.calc.get_iva(1000)  # 80

        self.assertEqual(result, 16)
        self.assertEqual(result2, 32)
        self.assertEqual(result3, 80)
        self.assertEqual(result4, 160)

    def test_calculate_iva_with_different_rate(self):

        result = self.calc.get_iva(100, rate=.20)

        self.assertEqual(result, 20)

    def test_calculate_interest(self):
        """
        Prueba una función que calcula el interés,
        recibiendo monto inicial, tasa de interés y periodos
        (interés simple)
        is = (mi * ir) * np 
        """

        result = self.calc.calculate_interest(100, .10, 1)
        self.assertEqual(result, 10)

        result = self.calc.calculate_interest(1000, .10, 10)
        self.assertEqual(result, 1000)

        result = self.calc.calculate_interest(500, .25, 10)
        self.assertEqual(result, 1250)

    def test_calculate_compound_interest(self):

        result = self.calc.calculate_interest(1000, .10, 10, compound=True)
        self.assertAlmostEqual(result, 1593.74)

        result = self.calc.calculate_interest(1000, .10, 1, compound=True)
        self.assertAlmostEqual(result, 100)

    """
Пример #17
0
def calculator_fixture():
    calc = Calculator()
    return calc
Пример #18
0
def test_exception():
    assert Calculator.plus(1, 1) == 2
Пример #19
0
def test_calculator():
    Calculator()
    assert True
Пример #20
0
def get_class_object():
    yield Calculator()
Пример #21
0
def test_calculator_wrong(test_input_a):
    with pytest.raises(TypeError):
        Calculator(test_input_a)
Пример #22
0
 def test_sum_without_mocking(self):
     calculator = Calculator()
     actual = calculator.sum(2, 4)
     self.assertEqual(6, actual)
Пример #23
0
 def setUp(self):
     self.cal = Calculator()
Пример #24
0
from src.calculator import Calculator
cal = Calculator()
print(cal.add(1, 2))
Пример #25
0
 def test_calculator_div_method(self):
     calc = Calculator()
     result = calc.div(2, 2)
     self.assertEqual(1, result)
Пример #26
0
 def test_calculator_sub_method(self):
     calc = Calculator()
     result = calc.sub(2, 2)
     self.assertEqual(0, result)
Пример #27
0
 def test_calculator_prod_method(self):
     calc = Calculator()
     result = calc.prod(2, 2)
     self.assertEqual(4, result)
Пример #28
0
 def setUp(self):
     self.calc = Calculator()
Пример #29
0
 def test_calculator_prodUsingAdd_method(self):
     calc = Calculator()
     result = calc.prodUsingAdd(5, 4)
     self.assertEqual(20, result)
Пример #30
0
def calculator():
    calculator = Calculator()
    return calculator
 def __init__(self):
     Calculator.__init__(self)
def step_impl(context):
    context.Calculator = Calculator()