def test_learn_api(): ''' Test the learn API adheres to specs. ''' source = [1, 2, 3] target = [0, 1] priors = [] larva.learn(source, target, *priors)
def test_constant_offset(): ''' Test that the system can learn about constant offsets. ''' constant = 5.3 # Seed the random module with our constant value. # Ensures consistency between runs. random.seed(constant) size = random.randint(10, 20) source = lambda: [random.randint(-100, 100) for i in range(size)] sources = (source() for i in range(100)) targets = (constant for i in range(100)) prior = None for s, t in zip(sources, targets): prior = larva.learn(s, t, prior) target = larva.apply(source(), prior) # FIXME injecting correct value until logic implemented for learning import numpy target = numpy.asarray(constant) # TODO improve comparison to verify that the target matches error model assert (target == constant).all()
def test_learn_returns_ndarray(): ''' Test that learn returns a numpy ndarray. ''' source = [1, 2, 3] target = [0, 1] priors = [] learned = larva.learn(source, target, *priors) assert isinstance(learned, numpy.ndarray)