@@ -0,0 +1,1540 @@
+import sqlite3%0Aimport string%0Aimport random%0A%0Aimport pytest%0A%0Afrom numba import float64, int64, jitclass%0Afrom slumba import sqlite_udaf, create_aggregate%0A%0Afrom ctypes import CDLL, c_char_p%0Afrom ctypes.util import find_library%0A%0A%0A@sqlite_udaf(float64(float64))%0A@jitclass(%5B%0A    ('total', float64),%0A    ('count', int64),%0A%5D)%0Aclass Avg(object):%0A    def __init__(self):%0A        self.total = 0.0%0A        self.count = 0%0A%0A    def step(self, value):%0A        self.total += value%0A        self.count += 1%0A%0A    def finalize(self):%0A        if not self.count:%0A            return None%0A        return self.total / self.count%0A%0A%0A%0A@pytest.fixture%0Adef con():%0A    con = sqlite3.connect(':memory:')%0A    con.execute(%22%22%22%0A        CREATE TABLE t (%0A            id INTEGER PRIMARY KEY,%0A            key VARCHAR(1),%0A            value DOUBLE PRECISION%0A        )%0A    %22%22%22)%0A    con.execute(%22%22%22%0A        CREATE TABLE s (%0A            id INTEGER PRIMARY KEY,%0A            key VARCHAR(1),%0A            value DOUBLE PRECISION%0A        )%0A    %22%22%22)%0A%0A    rows = %5B%0A        ('a', 1.0),%0A        ('a', 2.0),%0A        ('b', 3.0),%0A        ('c', 4.0),%0A        ('c', 5.0),%0A    %5D%0A    con.executemany('INSERT INTO t (key, value) VALUES (?, ?)', rows)%0A    create_aggregate(con, 'myavg', 1, Avg)%0A    return con%0A%0A%0Adef test_aggregate(con):%0A    result = list(con.execute('SELECT myavg(value) as c FROM t'))%0A    assert result == list(con.execute('SELECT avg(value) FROM t'))%0A%0A%0Adef test_aggregate_with_empty(con):%0A    result = list(con.execute('SELECT myavg(value) as c FROM s'))%0A    assert result == %5B(None,)%5D%0A

Add aggregate tests