Esempio n. 1
0
def test_20_million_insert_of_invoices(random_invoices):
    invoice_stats = InvoiceStats()
    t_insert_20_million_rows = process_time()
    invoice_stats.add_invoices(invoices=random_invoices)
    elapsed_time_insert_20_million_rows = process_time() - t_insert_20_million_rows

    LOGGER.info(
        f"elapsed_time_insert_20_million_rows: {elapsed_time_insert_20_million_rows} seconds"
    )

    invoice_stats.invoice_schema.validate(invoice_stats.invoices)

    t_get_median_20_million_rows = process_time()
    invoice_stats.get_median()
    elapsed_time_get_median_20_million_rows = process_time() - t_get_median_20_million_rows

    LOGGER.info(
        f"elapsed_time_get_median_20_million_rows: {elapsed_time_get_median_20_million_rows} seconds"
    )

    t_get_mean_20_million_rows = process_time()
    invoice_stats.get_mean()
    elapsed_time_get_mean_20_million_rows = process_time() - t_get_mean_20_million_rows

    LOGGER.info(f"elapsed_time_get_mean_20_million_rows: {elapsed_time_get_mean_20_million_rows}")

    LOGGER.info(f"\n{invoice_stats.invoice_stats.to_string()}\n")

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.shape[0] == 1
    assert invoice_stats.invoice_stats.shape[1] == 2

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == INVOICE_LIMIT
    assert invoice_stats.invoices.shape[1] == 2
Esempio n. 2
0
def test_get_median_failure(incorrect_invoice):
    invoice_stats = InvoiceStats()
    invoice_stats.add_invoice(incorrect_invoice)

    # force wrong value
    invoice_stats.invoices["invoice_value"] = "abc"

    with pytest.raises(Exception):
        invoice_stats.get_median()
Esempio n. 3
0
def test_add_remove_add(random_invoice, random_invoices, expected_mean, expected_median):
    invoice_stats = InvoiceStats()

    invoice_stats.add_invoices(invoices=random_invoices)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == len(random_invoices)
    assert invoice_stats.invoices.shape[1] == 2

    invoice_stats.get_mean()
    invoice_stats.get_median()

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.shape[0] == 1
    assert invoice_stats.invoice_stats.shape[1] == 2

    invoice_stats.add_invoice(invoice=random_invoice)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == len(random_invoices) + 1
    assert invoice_stats.invoices.shape[1] == 2

    invoice_stats.clear()

    # Check dimension of invoices
    assert invoice_stats.invoices.empty
    assert invoice_stats.invoices.empty

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.empty
    assert invoice_stats.invoice_stats.empty

    invoice_stats.add_invoice(invoice=random_invoice)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == 1
    assert invoice_stats.invoices.shape[1] == 2

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.empty
    assert invoice_stats.invoice_stats.empty

    invoice_stats.get_mean()
    invoice_stats.get_median()

    assert invoice_stats.invoice_stats.values.tolist()[0] == [999.0, 999.0]
def test_mean_and_median_of_invoices(random_invoices, expected_mean, expected_median):
    invoice_stats = InvoiceStats()

    invoice_stats.add_invoices(invoices=random_invoices)

    # Check dimension of invoices
    assert invoice_stats.invoices.shape[0] == len(random_invoices)
    assert invoice_stats.invoices.shape[1] == 2

    invoice_stats.get_mean()
    invoice_stats.get_median()

    # Check dimension of stats table
    assert invoice_stats.invoice_stats.shape[0] == 1
    assert invoice_stats.invoice_stats.shape[1] == 2

    # Validate that mean and median is correct
    LOGGER.info(
        f"{invoice_stats.invoice_stats.values.tolist()[0]} == {[expected_mean, expected_median]}"
    )
    assert invoice_stats.invoice_stats.values.tolist()[0] == [expected_mean, expected_median]