Exemplo n.º 1
0
def test_random():
    testcases = read_test_data("glibc/random.data")

    #TODO: add test for from_output, once growing error problem is resolved
    for testcase in testcases:
        gen = random.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert(next(gen) == output)
Exemplo n.º 2
0
def test_rand_r():
    testcases = read_test_data("mysql/rand.data", as_type=float)

    for i, testcase in enumerate(testcases):
        gen = rand.from_outputs(testcase.outputs[:2])
        for output in testcase.outputs[2:]:
            assert (next(gen) == output)

        gen = rand.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert (next(gen) == output)
Exemplo n.º 3
0
def test_rand_r():
    testcases = read_test_data("glibc/rand_r.data")

    for i, testcase in enumerate(testcases):
        gen = rand_r.from_outputs(testcase.outputs[:1])
        for output in testcase.outputs[1:]:
            assert(next(gen) == output)

        gen = rand_r.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert(next(gen) == output)
Exemplo n.º 4
0
def test_nextInt():
    testcases = read_test_data("java/nextInt.data")

    for testcase in testcases:
        gen = nextInt.from_outputs(testcase.outputs[:5])
        for output in testcase.outputs[5:]:
            assert(next(gen) == output)

        gen = nextInt.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert(next(gen) == output)
Exemplo n.º 5
0
def test_rand_r():
    testcases = read_test_data("mysql/rand.data", as_type=float)

    for i, testcase in enumerate(testcases):
        gen = rand.from_outputs(testcase.outputs[:2])
        for output in testcase.outputs[2:]:
            assert(next(gen) == output)

        gen = rand.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert(next(gen) == output)
Exemplo n.º 6
0
def test_nextLong():
    testcases = read_test_data("java/nextLong.data")

    for testcase in testcases:
        gen = nextLong.from_outputs(testcase.outputs[:1])
        for output in testcase.outputs[1:]:
            assert(next(gen) == output)

        gen = nextLong.from_seed(testcase.seed)
        for i, output in enumerate(testcase.outputs):
            assert(next(gen) == output)
Exemplo n.º 7
0
def test_rand():
    testcases = read_test_data("msvc/rand.data")

    for i, testcase in enumerate(testcases):
        gen = rand.from_outputs(testcase.outputs[:4])
        for output in testcase.outputs[4:]:
            assert (next(gen) == output)

        gen = rand.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert (next(gen) == output)
Exemplo n.º 8
0
def test_rand():
    testcases = read_test_data("msvc/rand.data")

    for i, testcase in enumerate(testcases):
        gen = rand.from_outputs(testcase.outputs[:4])
        for output in testcase.outputs[4:]:
            assert(next(gen) == output)

        gen = rand.from_seed(testcase.seed)
        for output in testcase.outputs:
            assert(next(gen) == output)
Exemplo n.º 9
0
class TestData:

    sources = read_test_data("test_data/unit_tests/sources.json", Sources)
    references = read_test_data(
        "test_data/unit_tests/references.json", References)

    empty_references = read_test_data(
        "test_data/unit_tests/empty_references.json", References)

    predictions = read_test_data(
        "test_data/unit_tests/predictions.json", Predictions)

    # predictions same as the references
    identical_predictions = read_test_data(
        "test_data/unit_tests/identical_predictions.json", Predictions)

    # empty predictions
    empty_predictions = read_test_data(
        "test_data/unit_tests/empty_predictions.json", Predictions)

    # predictions set to references reversed and punctuation removed.
    reversed_predictions = read_test_data(
        "test_data/unit_tests/reversed_predictions.json", Predictions)
Exemplo n.º 10
0
def gas_values_snapshot(pytestconfig):
    """Returns a GasValueSnapshoter, an object to assert gas values based on created snapshots"""
    snapshot_filename = "gas_values.csv"

    class GasValueSnapshoter:
        UNKNOWN = -1

        def __init__(self, data, *, update=False):
            """
            Creates gas values snapshots and let assert that the values did not change
            Snapshot data is updated when it does not exist, or when  `update` is set. In this case
            tests always succeed.
            :param data: The snapshot data
            :param update: True, if existing values should be updated or not
            """
            self.update = update
            self.data = data

        def assert_gas_values_match_for_call(self,
                                             key,
                                             web3,
                                             contract_call,
                                             transaction_options=None):
            """
            Assert that the gas values of a contract call are correct and did not change.
            This will execute the contract call once.
            """
            if key not in self.data or self.update:
                gas_values = find_gas_values_for_call(
                    web3,
                    contract_call,
                    transaction_options=transaction_options)
                self.data[key] = gas_values
            else:
                assert_gas_values_for_call(
                    web3,
                    contract_call,
                    transaction_options=transaction_options,
                    gas_cost_estimation=self.data[key].cost,
                    gas_limit=self.data[key].limit,
                )

        def assert_gas_costs_match(self, key, gas_cost, *, abs_delta=100):
            """Assert that the gas cost did not change within the allowed delta.
            This will not execute any transaction and can thus not check
            the gas limit."""
            if key not in self.data or self.update:
                self.data[key] = GasValues(gas_cost, self.UNKNOWN)
            else:
                assert_gas_costs(gas_cost,
                                 self.data[key].cost,
                                 abs_delta=abs_delta)

    snapshot_path = pathlib.Path(
        __file__).parent.absolute() / snapshot_filename
    snapshoter = GasValueSnapshoter(
        data=read_test_data(snapshot_path, data_class=GasValues),
        update=pytestconfig.getoption(UPDATE_GAS_VALUES_OPTION, default=False),
    )

    yield snapshoter

    write_test_data(snapshot_path, ["KEY", "GAS_COST", "GAS_LIMIT"],
                    snapshoter.data)
Exemplo n.º 11
0
import os

import unittest

import numpy as np
from numba.typed import List

import stlearn as st
import scanpy as sc
from tests.utils import read_test_data

import stlearn.tools.microenv.cci.het_helpers as het_hs
import stlearn.tools.microenv.cci.het as het

global adata
adata = read_test_data()


class TestCCI(unittest.TestCase):
    """Tests for `stlearn` CCI capability."""

    def setUp(self) -> None:
        """Setup some basic test-cases as sanity checks."""

        ##### Unit neighbourhood, containing just 1 spot and 6 neighbours ######
        """
        * A is the middle spot, B/C/D/E/F/G are the neighbouring spots clock-
                                                  wise starting at the top-left.
        """
        spot_bcs = np.array(["A", "B", "C", "D", "E", "F", "G"])
        neigh_dict = {