Example #1
0
def test_price_from_rate():
    """Tests the price generated from the rate."""

    pc = Desktop(chassis=ComputerChassis.Tower)
    hdd = HardDrive(size=476940)
    hdd.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
    cpu = Processor(cores=2, speed=3.4)
    cpu.actions_one.add(BenchmarkProcessor(rate=27136.44))
    pc.components |= {
        hdd,
        RamModule(size=4096, speed=1600),
        RamModule(size=2048, speed=1067), cpu
    }

    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.A,
               functionality_range=FunctionalityRange.A,
               device=pc)
    _, price = RateComputer.compute(pc)

    assert price.price == Decimal('78.2001')
    assert price.retailer.standard.amount == Decimal('34.7502')
    assert price.platform.standard.amount == Decimal('15.9821')
    assert price.refurbisher.standard.amount == Decimal('27.4678')
    assert price.price >= price.retailer.standard.amount + price.platform.standard.amount \
           + price.refurbisher.standard.amount
    assert price.retailer.warranty2.amount == Decimal('46.9103')
    assert price.platform.warranty2.amount == Decimal('21.5735')
    assert price.refurbisher.warranty2.amount == Decimal('37.0864')
    assert price.warranty2 == Decimal('105.57')
def test_rate_no_data_storage():
    """Test without data storage devices."""

    hdd_null = HardDrive()
    hdd_null.actions_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0))
    data_storage_rate = DataStorageRate().compute([hdd_null])
    assert data_storage_rate is None
def test_rate_data_storage_size_is_null():
    """Test where input DataStorage.size = NULL, BenchmarkDataStorage.read_speed = 0,
    BenchmarkDataStorage.write_speed = 0 is like no DataStorage has been detected;
    """

    hdd_null = HardDrive(size=None)
    hdd_null.actions_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0))

    data_storage_rate = DataStorageRate().compute([hdd_null])
    assert data_storage_rate is None
def test_rate_computer_multiple_ram_module():
    """Test rate computer characteristics:
        - only 1 module ram
        - processor 2 cores

    Data get it from R score from DH pc with id = 79

    pc_79 = Computer()
    price = VeryLow
    hdd_81 = HardDrive(size=76319)
    hdd_81.actions_one.add(BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))
    ram1 = RamModule(size=512, speed=667)
    ram2 = RamModule(size=512, speed=800)
    ram3 = RamModule(size=512, speed=667)
    ram4 = RamModule(size=512, speed=533)
    cpu = Processor(cores=1, speed=1.6)
    cpu.actions_one.add(BenchmarkProcessor(rate=3192.34))
    pc_79.components.add(hdd_81, ram1, ram2, ram3, ram4, cpu)
    # add functionality and appearance range
    rate_pc_79 = WorkbenchRate(appearance_range=AppearanceRange.C,
        functionality_range=FunctionalityRange.A)
    # add component rate
    HDD_rate = 2.61
    RAM_rate = 1.99
    Processor_rate = 1
    Rating = 1.58
    """

    pc_test = Desktop(chassis=ComputerChassis.Tower)
    data_storage = HardDrive(size=76319)
    data_storage.actions_one.add(
        BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))
    cpu = Processor(cores=1, speed=1.6)
    cpu.actions_one.add(BenchmarkProcessor(rate=3192.34))
    pc_test.components |= {
        data_storage,
        RamModule(size=512, speed=667),
        RamModule(size=512, speed=800),
        RamModule(size=512, speed=667),
        RamModule(size=512, speed=533), cpu
    }
    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.C,
               functionality_range=FunctionalityRange.A,
               device=pc_test)
    # Compute all components rates and general rating
    rate_pc = RateAlgorithm().compute(pc_test)

    assert math.isclose(rate_pc.ram, 1.99, rel_tol=0.001)

    assert math.isclose(rate_pc.data_storage, 2.61, rel_tol=0.001)

    assert math.isclose(rate_pc.processor, 1, rel_tol=0.001)

    assert rate_pc.rating == 1.37
def test_rate_computer_1193():
    """Test rate computer characteristics:
        - 2 module ram
        - processor with 2 cores

    Data get it from R score from DH pc with id = 1193

    pc_1193 = Computer()
    price = 92.2
    hdd_1969 = HardDrive(size=476940)
    hdd_1969.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
    ram1 = RamModule(size=4096, speed=1600)
    ram2 = RamModule(size=2048, speed=1067)
    cpu = Processor(cores=2, speed=3.4)
    cpu.actions_one.add(BenchmarkProcessor(rate=27136.44))
    pc_1193.components.add(hdd_1969, ram1, ram2, cpu)
    rate_pc_1193 = WorkbenchRate(appearance_range=AppearanceRange.A,
        functionality_range=FunctionalityRange.A)
    HDD_rate = 4.02
    RAM_rate = 3.79
    Processor_rate = 3.95
    Rating = 4.61
    """

    pc_test = Desktop(chassis=ComputerChassis.Tower)
    data_storage = HardDrive(size=476940)
    data_storage.actions_one.add(
        BenchmarkDataStorage(read_speed=126, write_speed=29.8))
    cpu = Processor(cores=2, speed=3.4)
    cpu.actions_one.add(BenchmarkProcessor(rate=27136.44))
    pc_test.components |= {
        data_storage,
        RamModule(size=4096, speed=1600),
        RamModule(size=2048, speed=1067), cpu
    }
    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.A,
               functionality_range=FunctionalityRange.A,
               device=pc_test)

    # Compute all components rates and general rating
    rate_pc = RateAlgorithm().compute(pc_test)

    assert math.isclose(rate_pc.ram, 3.79, rel_tol=0.001)

    assert math.isclose(rate_pc.data_storage, 4.02, rel_tol=0.001)

    assert math.isclose(rate_pc.processor, 3.95, rel_tol=0.001)

    assert math.isclose(rate_pc.rating, 3.91, rel_tol=0.001)
def test_rate_data_storage_rate():
    """Test to check if compute data storage rate have same value than
    previous score version.
    """

    hdd_1969 = HardDrive(size=476940)
    hdd_1969.actions_one.add(
        BenchmarkDataStorage(read_speed=126, write_speed=29.8))

    data_storage_rate = DataStorageRate().compute([hdd_1969])

    assert math.isclose(data_storage_rate, 4.02, rel_tol=0.001)

    hdd_3054 = HardDrive(size=476940)
    hdd_3054.actions_one.add(
        BenchmarkDataStorage(read_speed=158, write_speed=34.7))

    # calculate DataStorage Rate
    data_storage_rate = DataStorageRate().compute([hdd_3054])

    assert math.isclose(data_storage_rate, 4.07, rel_tol=0.001)

    hdd_81 = HardDrive(size=76319)
    hdd_81.actions_one.add(
        BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))

    data_storage_rate = DataStorageRate().compute([hdd_81])

    assert math.isclose(data_storage_rate, 2.61, rel_tol=0.001)

    hdd_1556 = HardDrive(size=152587)
    hdd_1556.actions_one.add(
        BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))

    data_storage_rate = DataStorageRate().compute([hdd_1556])

    assert math.isclose(data_storage_rate, 3.70, rel_tol=0.001)
def test_rate_computer_one_ram_module():
    """Test rate computer characteristics:
        - only 1 module ram
        - processor 2 cores

    Data get it from R score from DH pc with id = 798

    pc_798 = Computer()
    price = 50
    hdd_1556 = HardDrive(size=152587)
    hdd_1556.actions_one.add(BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))
    ram0 = RamModule(size=0, speed=None)
    cpu = Processor(cores=2, speed=2.5)
    cpu.actions_one.add(BenchmarkProcessor(rate=9974.3))
    pc_798.components.add(hdd_1556, ram0, cpu)
    # add functionality and appearance range
    rate_pc_798 = WorkbenchRate(appearance_range=AppearanceRange.B,
        functionality_range=FunctionalityRange.A)
    # add component rate
    HDD_rate = 3.7
    RAM_rate = 1
    Processor_rate = 4.09
    Rating = 2.5
    """

    pc_test = Desktop(chassis=ComputerChassis.Tower)
    data_storage = HardDrive(size=152587)
    data_storage.actions_one.add(
        BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))
    cpu = Processor(cores=2, speed=2.5)
    cpu.actions_one.add(BenchmarkProcessor(rate=9974.3))
    pc_test.components |= {data_storage, RamModule(size=0, speed=None), cpu}
    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.B,
               functionality_range=FunctionalityRange.A,
               device=pc_test)

    # Compute all components rates and general rating
    rate_pc = RateAlgorithm().compute(pc_test)

    assert math.isclose(rate_pc.ram, 1, rel_tol=0.001)

    assert math.isclose(rate_pc.data_storage, 3.7, rel_tol=0.001)

    assert math.isclose(rate_pc.processor, 4.09, rel_tol=0.001)

    assert math.isclose(rate_pc.rating, 2.1, rel_tol=0.001)
def test_rate_computer_1201():
    """Test rate computer characteristics:
        - only 1 module ram
        - processor 2 cores

    Data get it from R score from DH pc with id = 1201

    pc_1201 = Computer()
    price = 69.6
    hdd_3054 = HardDrive(size=476940)
    hdd_3054.actions_one.add(BenchmarkDataStorage(read_speed=158, write_speed=34.7))
    ram1 = RamModule(size=2048, speed=1333)
    cpu = Processor(cores=2, speed=3.3)
    cpu.actions_one.add(BenchmarkProcessor(rate=26339.48))
    pc_1201.components.add(hdd_3054, ram1, cpu)
    rate_pc_1201 = WorkbenchRate(appearance_range=AppearanceRange.B,
        functionality_range=FunctionalityRange.A)
    HDD_rate = 4.07
    RAM_rate = 2.02
    Processor_rate = 3.93
    Rating = 3.48
    """

    pc_test = Desktop(chassis=ComputerChassis.Tower)
    data_storage = HardDrive(size=476940)
    data_storage.actions_one.add(
        BenchmarkDataStorage(read_speed=158, write_speed=34.7))
    cpu = Processor(cores=2, speed=3.3)
    cpu.actions_one.add(BenchmarkProcessor(rate=26339.48))
    pc_test.components |= {data_storage, RamModule(size=2048, speed=1333), cpu}
    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.B,
               functionality_range=FunctionalityRange.A,
               device=pc_test)

    # Compute all components rates and general rating
    rate_pc = RateAlgorithm().compute(pc_test)

    assert math.isclose(rate_pc.ram, 2.02, rel_tol=0.001)

    assert math.isclose(rate_pc.data_storage, 4.07, rel_tol=0.001)

    assert math.isclose(rate_pc.processor, 3.93, rel_tol=0.001)

    assert math.isclose(rate_pc.rating, 3.08, rel_tol=0.001)
Example #9
0
def test_multiple_rates(user: UserClient):
    """Tests submitting two rates from Workbench,
    ensuring that the tests / benchmarks...
    from the first rate do not contaminate the second rate.

    This ensures that rates only takes all the correct actions
    and components rates in case device have new tests/benchmarks.
    """

    pc = Desktop(chassis=ComputerChassis.Tower)
    hdd = HardDrive(size=476940)
    hdd.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
    cpu = Processor(cores=2, speed=3.4)
    cpu.actions_one.add(BenchmarkProcessor(rate=27136.44))
    pc.components = {
        hdd,
        RamModule(size=4096, speed=1600),
        RamModule(size=2048, speed=1600), cpu
    }

    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.A,
               functionality_range=FunctionalityRange.A,
               device=pc)

    rate1, price1 = RateComputer.compute(pc)

    # asserts rate1 ...
    assert rate1.data_storage == 4.02
    assert rate1.processor == 3.95
    assert rate1.ram == 3.8

    assert rate1.appearance is None
    assert rate1.functionality is None

    assert rate1.rating == 3.92

    assert price1.price == Decimal('78.4001')

    cpu.actions_one.add(BenchmarkProcessor(rate=16069.44))
    ssd = SolidStateDrive(size=476940)
    ssd.actions_one.add(BenchmarkDataStorage(read_speed=222, write_speed=111))
    pc.components |= {
        ssd,
        RamModule(size=2048, speed=1067),
        RamModule(size=2048, speed=1067),
    }

    # Add test visual with functionality and appearance range
    VisualTest(appearance_range=AppearanceRange.B,
               functionality_range=FunctionalityRange.B,
               device=pc)

    rate2, price2 = RateComputer.compute(pc)

    assert rate2.data_storage == 4.3
    assert rate2.processor == 3.78
    assert rate2.ram == 3.95

    assert rate2.appearance is None
    assert rate2.functionality is None

    assert rate2.rating == 3.93

    assert price2.price == Decimal('78.6001')