<commit_before>#!/usr/bin/env python

from stella import stella
from random import randint
import sys

def addition(a,b):       return a+b
def subtraction(a,b):    return a-b
def multiplication(a,b): return a*b
def division(a,b):       return a/b
def floor_division(a,b): return a//b

arglist = [(-1,0), (84, -42), (1.0, 1), (0,1), (randint(0, 1000000), randint(0, 1000000)), (-1*randint(0, 1000000), randint(0, 1000000))]
def make_test(f):
    def perform_test(f):
        for (a,b) in arglist:
            x = f(a,b)
            y = stella(f)(a,b)
            assert x == y and type(x) == type(y)
    sys.modules[__name__].__dict__["test_" + f.__name__] = lambda: perform_test(f)
for f in [addition, subtraction, multiplication]:
    make_test(f)

delta = 0.0000001
arglist = [(0,1), (5,2), (5.0,2), (4.0,4), (-5,2), (5.0,-2), (randint(0, 1000000), randint(1, 1000000))]
def make_test(f):
    def perform_test(f):
        for (a,b) in arglist:
            x = f(a,b)
            y = stella(f)(a,b)
            assert x-y < delta and type(x) == type(y)
    sys.modules[__name__].__dict__["test_" + f.__name__] = lambda: perform_test(f)
for f in [division, floor_division]:
    make_test(f)

if __name__ == '__main__':
    print(stella(addition)(41, 1))
    #print(stella(addition)(43, -1))
    print(stella(subtraction)(44,2))
    print(stella(multiplication)(21,2))
    print(stella(division)(42,10))
    print(stella(floor_division)(85,2.0))
    print(stella(floor_division)(85,-2.0))<commit_msg>More complex math test<commit_after>#!/usr/bin/env python

from stella import stella
from random import randint
import sys

def addition(a,b):       return a+b
def subtraction(a,b):    return a-b
def multiplication(a,b): return a*b
def division(a,b):       return a/b
def floor_division(a,b): return a//b
def chained(a,b): return (a-b)/b*a;

arglist1 = [(-1,0), (84, -42), (1.0, 1), (0,1), (randint(0, 1000000), randint(0, 1000000)), (-1*randint(0, 1000000), randint(0, 1000000))]
def make_test(f, arglist):
    def perform_test(f, arglist):
        for (a,b) in arglist:
            x = f(a,b)
            y = stella(f)(a,b)
            assert x == y and type(x) == type(y)
    sys.modules[__name__].__dict__["test_" + f.__name__] = lambda: perform_test(f, arglist)
for f in [addition, subtraction, multiplication]:
    make_test(f, arglist1)

delta = 0.0000001
arglist2 = [(0,1), (5,2), (5.0,2), (4.0,4), (-5,2), (5.0,-2), (randint(0, 1000000), randint(1, 1000000))]
def make_test(f, arglist):
    def perform_test(f, arglist):
        for (a,b) in arglist:
            x = f(a,b)
            y = stella(f)(a,b)
            assert x-y < delta and type(x) == type(y)
    sys.modules[__name__].__dict__["test_" + f.__name__] = lambda: perform_test(f, arglist)
for f in [division, floor_division]:
    make_test(f, arglist2)

#delta = 0.00001
make_test(chained, arglist2)

if __name__ == '__main__':
    print(stella(addition)(41, 1))
    print(stella(addition)(43, -1))
    print(stella(subtraction)(44,2))
    print(stella(multiplication)(21,2))
    print(stella(division)(42,10))
    print(stella(floor_division)(85,2.0))
    print(stella(floor_division)(85,-2.0))
    x = chained(5,2)
    y = stella(chained)(5,2)
    print("chained difference: {0:.10f}".format(x-y))
{'fraction_non_alphanumeric': 0.1829305598042215, 'fraction_numerical': 0.07096971550933007, 'mean_word_length': 3.5862552594670407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3052314', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1273, 'n_words': 283}