<commit_before>import unittest
import random
import numpy as np

import karta
import karta.vector.rtree as rtree

class TestGeom(object):
    def __init__(self, bbox):
        self.bbox = bbox

class RTreeTests(unittest.TestCase):

    def test_build(self):
        np.random.seed(49)
        geoms = []
        for i in range(1000):
            offset = np.random.rand(1, 2)*5
            line = karta.Line(np.random.rand(5, 2)+offset)
            geoms.append(line)

        tree = rtree.build_tree(geoms, max_children=25)
        self.assertEqual(type(tree), rtree.NonLeafNode)
        self.assertEqual(rtree.depth(tree), 3)
        self.assertEqual(len(tree.children), 6)
        return

    def test_leaf_split(self):
        node = rtree.LeafNode((0, 0, 1, 1), None, max_children=10)
        node.children = [TestGeom((0.1*i, 0.1*i, 0.1*i+0.05, 0.1*i+0.05))
                         for i in range(10)]
        random.seed(49)
        random.shuffle(node.children)
        newnodes = node.split()
        self.assertEqual(len(newnodes[0].children), 6)
        self.assertEqual(len(newnodes[1].children), 4)
        for child in node.children:
            self.assertTrue((child in newnodes[0].children) or
                            (child in newnodes[1].children))
        self.assertTrue(newnodes[0].parent is None)
        self.assertTrue(newnodes[1].parent is None)

    def test_nonleaf_split(self):
        node = rtree.NonLeafNode((0, 0, 1, 1), None, max_children=10)
        node.children = [rtree.LeafNode((0.1*i, 0.1*i, 0.1*i+0.05, 0.1*i+0.05), None)
                         for i in range(10)]
        random.seed(49)
        random.shuffle(node.children)
        newnodes = node.split()
        self.assertEqual(len(newnodes[0].children), 6)
        self.assertEqual(len(newnodes[1].children), 4)
        for child in node.children:
            self.assertTrue((child in newnodes[0].children) or
                            (child in newnodes[1].children))
        self.assertTrue(newnodes[0].parent is None)
        self.assertTrue(newnodes[1].parent is None)<commit_msg>use np.random rather than random library module<commit_after>import unittest
import numpy as np

import karta
import karta.vector.rtree as rtree

class TestGeom(object):
    def __init__(self, bbox):
        self.bbox = bbox

class RTreeTests(unittest.TestCase):

    def test_build(self):
        np.random.seed(49)
        geoms = []
        for i in range(1000):
            offset = np.random.rand(1, 2)*5
            line = karta.Line(np.random.rand(5, 2)+offset)
            geoms.append(line)

        tree = rtree.build_tree(geoms, max_children=25)
        self.assertEqual(type(tree), rtree.NonLeafNode)
        self.assertEqual(rtree.depth(tree), 3)
        self.assertEqual(len(tree.children), 6)
        return

    def test_leaf_split(self):
        node = rtree.LeafNode((0, 0, 1, 1), None, max_children=10)
        node.children = [TestGeom((0.1*i, 0.1*i, 0.1*i+0.05, 0.1*i+0.05))
                         for i in range(10)]
        np.random.seed(49)
        np.random.shuffle(node.children)
        newnodes = node.split()
        self.assertEqual(len(newnodes[0].children), 6)
        self.assertEqual(len(newnodes[1].children), 4)
        for child in node.children:
            self.assertTrue((child in newnodes[0].children) or
                            (child in newnodes[1].children))
        self.assertTrue(newnodes[0].parent is None)
        self.assertTrue(newnodes[1].parent is None)

    def test_nonleaf_split(self):
        node = rtree.NonLeafNode((0, 0, 1, 1), None, max_children=10)
        node.children = [rtree.LeafNode((0.1*i, 0.1*i, 0.1*i+0.05, 0.1*i+0.05), None)
                         for i in range(10)]
        np.random.seed(49)
        np.random.shuffle(node.children)
        newnodes = node.split()
        self.assertEqual(len(newnodes[0].children), 6)
        self.assertEqual(len(newnodes[1].children), 4)
        for child in node.children:
            self.assertTrue((child in newnodes[0].children) or
                            (child in newnodes[1].children))
        self.assertTrue(newnodes[0].parent is None)
        self.assertTrue(newnodes[1].parent is None)
{'fraction_non_alphanumeric': 0.13021821631878558, 'fraction_numerical': 0.03747628083491461, 'mean_word_length': 2.29453125, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1317073', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1390, 'n_words': 273}