예제 #1
0
    def test_adding(self):
        """Test adding functionality"""
        adder = Adder()

        for i in range(-10, 10):
            for j in range(-10, 10):
                self.assertEqual(i + j, adder.calc(i, j))
예제 #2
0
def test_adder_meta():
    now = datetime.datetime.now()
    date_time = str(now).split(' ')

    current_date = date_time[0]

    add = Adder(current_date, '22:00:00')
    conn = sqlite3.connect('src/weather.db')
    add.add_meta_weather_forecasts(conn)
예제 #3
0
def test_adder_owp_stress():
    now = datetime.datetime.now()
    date_time = str(now).split(' ')

    current_date = date_time[0]

    for i in range(0, 200):
        add = Adder(current_date, '22:00:00')
        conn = sqlite3.connect('src/weather.db')
        add.add_owp_forecasts(conn)
        conn.close()
예제 #4
0
 def final_order(self):
     self._strategy.order_type = self._order_type
     bp = self.calculate_bonus_pack()
     milk = bp * self._strategy.calculate_bonus_on('milk')
     dark = bp * self._strategy.calculate_bonus_on('dark')
     white = bp * self._strategy.calculate_bonus_on('white')
     bonus = [milk, dark, white]
     initial_purchase = self.calculate_initial_buy()
     adder = Adder(self._order_type, initial_purchase)
     self._adder_final_no_text = adder.adder(bonus)
     r = adder.adder(bonus)
     return 'milk {},dark {},white {}'.format(r[0], r[1], r[2])
예제 #5
0
 def setUp(self):
     self.adder = Adder()
     self.subtracter = Subtracter()
     self.multiplier = Multiplier()
     self.divider = Divider()
     self.calculator = Calculator(self.adder, self.subtracter,
                                  self.multiplier, self.divider)
예제 #6
0
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)

        # pulled from the unittest file, testing that there is not
        # a missing operand
        with self.assertRaises(InsufficientOperands):
            calculator.add()
 def __init__(self):
     self.output = []
     self.shift_register1 = Lfsr(input("seed for the first RFSR:"),[8,12,20,25])
     self.shift_register2 = Lfsr(input("seed for the second RFSR:"),[21,16,24,31])
     self.shift_register3 = Lfsr(input("seed for the third RFSR:"),[4,24,28,33])
     self.shift_register4 = Lfsr(input("seed for the fourth RFSR:"),[4,28,36,39])
     self.r1 = Register(input("seed for the register R1:"))
     self.r2 = Register(self.r1.output)
     self.t1 = InternalState()
     self.t2 = InternalState()
     self.adder1 = Adder()
     self.adder2 = Adder()
     self.iz = Iz()
     self.xor_iz_t2 = Xor([self.t2.output,self.iz.output])
     self.xor_t1_xor = Xor([self.t1.output,self.xor_iz_t2.output])
     self.xor_zt = Xor([self.shift_register1.output,self.shift_register2.output,
                     self.shift_register3.output,self.shift_register4.output,self.r1.least_significant()])
    def test_multiplication(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(10)
        calculator.enter_number(12)

        result = calculator.multiply()
        self.assertEqual(120, result)
        del calculator
    def test_subtraction(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(-2)
        calculator.enter_number(10)

        result = calculator.add()
        self.assertEqual(8, result)
        del calculator
    def test_subtraction_error(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(24)
        calculator.enter_number(12)

        result = calculator.subtract()
        self.assertEqual(12, result)
        del calculator
    def test_division(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(2)
        calculator.enter_number(10)

        result = calculator.divide()
        self.assertEqual(5, result)
        del calculator
예제 #12
0
    def setUp(self):
        """Setup function to add modules to calculator"""
        self.adder = Adder()
        self.subtracter = Subtracter()
        self.multiplier = Multiplier()
        self.divider = Divider()

        self.calculator = Calculator(self.adder, self.subtracter,
                                     self.multiplier, self.divider)
class E0Generator:
    def __init__(self):
        self.output = []
        self.shift_register1 = Lfsr(input("seed for the first RFSR:"),[8,12,20,25])
        self.shift_register2 = Lfsr(input("seed for the second RFSR:"),[21,16,24,31])
        self.shift_register3 = Lfsr(input("seed for the third RFSR:"),[4,24,28,33])
        self.shift_register4 = Lfsr(input("seed for the fourth RFSR:"),[4,28,36,39])
        self.r1 = Register(input("seed for the register R1:"))
        self.r2 = Register(self.r1.output)
        self.t1 = InternalState()
        self.t2 = InternalState()
        self.adder1 = Adder()
        self.adder2 = Adder()
        self.iz = Iz()
        self.xor_iz_t2 = Xor([self.t2.output,self.iz.output])
        self.xor_t1_xor = Xor([self.t1.output,self.xor_iz_t2.output])
        self.xor_zt = Xor([self.shift_register1.output,self.shift_register2.output,
                        self.shift_register3.output,self.shift_register4.output,self.r1.least_significant()])

    def execute(self,exit_bits_number):
        for i in range (exit_bits_number):
            self.t1.execute(self.r1.output)
            self.t2.execute(self.r2.output)
            self.t2.t2_output()
            self.adder1.execute([self.shift_register1.shift_right(),self.shift_register2.shift_right(),
                                  self.shift_register3.shift_right(),self.shift_register4.shift_right()])
            self.adder2.execute([self.adder1.output,self.r1.int_output()])
            self.iz.execute(self.adder2.output)
            self.xor_iz_t2.update_registers([self.t2.output, self.iz.output])
            self.xor_iz_t2.binary_xor()
            self.xor_t1_xor.update_registers([self.t1.output, self.xor_iz_t2.output])
            self.xor_t1_xor.binary_xor()
            self.xor_zt = Xor([self.shift_register1.output, self.shift_register2.output,
                               self.shift_register3.output, self.shift_register4.output, self.r1.least_significant()])
            self.output.append(self.xor_zt.xor())
            self.r1 = Register(self.xor_t1_xor.output)
            self.r2 = Register(self.r1.output)
    def test_module(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(3)
        calculator.enter_number(4)

        self.assertEqual(12, calculator.multiply())

        calculator.enter_number(2)

        self.assertEqual(10, calculator.subtract())

        calculator.enter_number(10)

        self.assertEqual(calculator.add(), 20)

        calculator.enter_number(5)

        result = calculator.divide()

        self.assertEqual(4, result)
예제 #15
0
    def test_module(self):
        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
예제 #16
0
    def test_module(self):

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        r1 = calculator.multiply()
        print('multiplication result:', r1)
        calculator.enter_number(46)

        r2 = calculator.add()
        print('addition result:', r2)
        calculator.enter_number(8)

        r3 = calculator.divide()
        print('division result:', r3)
        calculator.enter_number(1)

        result = calculator.subtract()
        print('result after final step of subtraction:', result)
        self.assertEqual(6, result)
예제 #17
0
    def test_modules(self):
        """Function to test each of the modules and function calls"""

        calculator = Calculator(Adder(), Subtracter(), Multiplier(), Divider())

        calculator.enter_number(5)
        calculator.enter_number(2)

        calculator.multiply()

        calculator.enter_number(46)

        calculator.add()

        calculator.enter_number(8)

        calculator.divide()

        calculator.enter_number(1)

        result = calculator.subtract()

        self.assertEqual(6, result)
예제 #18
0
    def test_adding(self):
        adder = Adder()

        for i in range(-10, 10):
            for j in range(-10, 10):
                self.assertEqual(i + j, adder.calc(i, j))
예제 #19
0
    expected = [(a + b) & mask for a, b in zip(data_a, data_b)]

    # for a, b, r in zip(data_a, data_b, expected):
    #    dut._log.info("[a]:{:02X}, [b]:{:02X}, [r]:{:02X}".format(a, b, r))

    send_a = cocotb.fork(stream_input_a.send(data_a))
    send_b = cocotb.fork(stream_input_b.send(data_b))
    send_a.join()
    send_b.join()

    received = await stream_output.recv(N)

    for expctd, rcvd in zip(expected, received):
        if expctd != rcvd:
            dut._log.info("Expected {} Got {}".format(expctd, rcvd))
            raise TestFailure("Test failed")

    raise TestSuccess("Test passed")


if __name__ == '__main__':
    core = Adder(5)
    run(core,
        'test_adder',
        ports=[
            *list(core.a.fields.values()), *list(core.b.fields.values()),
            *list(core.r.fields.values())
        ],
        vcd_file='adder.vcd')
예제 #20
0
def test_adder_unreal_temp():
    adder = Adder('2000-06-13', '22:00:00')
    conn = sqlite3.connect('src/weather.db')

    with pytest.raises(ValueError):
        adder.add_real_weather(conn, '+1000000000000000')
예제 #21
0
def test_adder():
    from adder import Adder
    assert Adder(3).add(5) == 8
    assert Adder(2).add(7) == 9
예제 #22
0
def test_adder_incorrect_input_temp_2():
    adder = Adder('2000-06-13', '22:00:00')
    conn = sqlite3.connect('src/weather.db')

    with pytest.raises(ValueError):
        adder.add_real_weather(conn, '+2q')
예제 #23
0
    def test_adding(self):
        adder = Adder()

        for x in range(-5, 10):
            for y in range(-5, 10):
                self.assertEqual(x + y, adder.calc(x, y))
예제 #24
0
 def test_sum_list(self):
     self.assertEqual(Adder().sum_list([1, 2, 3]), 6)
예제 #25
0
 def test_sum(self):
     self.assertEqual(Adder().sum(1, 2), 3)
예제 #26
0
from step import Step
from adder import Adder
from scheduler import Scheduler
import component
import math

if __name__ == "__main__":
    print("------------------------------\n")
    print("t = 0")

    step1 = Step(0.65, 1, -3, "01")
    step2 = Step(0.35, 0, 1, "02")
    step3 = Step(1, 0, 1, "03")
    step4 = Step(1.5, 0, 4, "04")

    adder = Adder(math.inf)

    print(component.components)

    port1 = component.Port(step1, [adder], "01")
    port2 = component.Port(step2, [adder], "02")
    port3 = component.Port(step3, [adder], "03")
    port4 = component.Port(step4, [adder], "04")

    step1.set_port(port1.name, port1)
    step2.set_port(port2.name, port2)
    step3.set_port(port3.name, port3)
    step4.set_port(port4.name, port4)

    adder.set_port(port1.name, port1)
    adder.set_port(port4.name, port4)
예제 #27
0
from nmigen_cocotb import run
from adder import Adder

if __name__ == '__main__':
    #inicializo el adder con la cantidad de bits que quiero en las entradas/salida. Luego corro los tests que se encuentran en test.py y se guarda la waveform

    core = Adder(3)
    run(core,
        'test',
        ports=[
            *list(core.a.fields.values()), *list(core.b.fields.values()),
            *list(core.r.fields.values())
        ],
        vcd_file='adder.vcd')
예제 #28
0
from step import Step
from adder import Adder
from integrateur import Integrateur
from qss import Qss
from evenement import Evenement
import matplotlib.pyplot as plt

temps = 0
temps_fin = 10
liste_comp = [
    Step(1, 1, -3, 0.65, [Evenement.XV]),
    Step(2, 0, 1, 0.35, [Evenement.XV]),
    Step(3, 0, 1, 1, [Evenement.XV]),
    Step(4, 0, 4, 1.5, [Evenement.XV]),
    Adder([Evenement.XV], [Evenement.X_POINT]),
    Integrateur([Evenement.X_POINT], [Evenement.RES]),
    Qss([Evenement.X_POINT], [Evenement.QI])
]
liste_points = []
liste_qss = []
liste_somme = []
liste_temps1 = []
liste_temps2 = []
liste_temps3 = []
while (temps <= temps_fin):
    ta_min = liste_comp[0].get_ta()
    for i in range(1, len(liste_comp)):
        tmp = liste_comp[i].get_ta()
        if ta_min > tmp:
            ta_min = tmp
예제 #29
0
 def test_adder(self):
     a = Adder(data=[])
     self.assertRaises(NotImplementedError, a.add, [])
예제 #30
0
 def test_formatter(self):
     formatter = Adder('white', 3)
     print("test_formatter...\n\n")
     print(formatter.out)
     result = list(map(add, formatter.out, formatter.out))
     self.assertEqual(result, formatter.adder(formatter.out))