<commit_before>import time
import os
import unittest

from hecuba import config
from hecuba import StorageDict


class DictSet(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str, k2:int>, s1:set<int, int>>
    '''

class DictSet2(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str, k2:int>, s1:set<str>>
    '''

class DictSet3(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str, k2:int>, s1:set<int>>
    '''

class DictSet4(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str>, s1:set<int>>
    '''


class EmbeddedSetTest(unittest.TestCase):

    def testAddRemove(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet2("pruebas0.dictset")
        d["1", 1] = {"1"}
        d["2", 2] = {"1", "2", "3"}

        self.assertTrue("1" in d["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d["2", 2])

        d["2", 2].remove("2")
        self.assertRaises(Exception, d["2", 2].__contains__, "2")

        d["2", 2].add("2")
        self.assertTrue("2" in d["2", 2])
        self.assertEqual(1, len(d["1", 1]))
        self.assertEqual(3, len(d["2", 2]))

    def testDoNotCollide(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet2("pruebas0.dictset")
        d["1", 1] = {"1"}
        d["2", 2] = {"1", "2", "3"}

        self.assertTrue("1" in d["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d["2", 2])

        del d
        d2 = DictSet2("pruebas0.dictset")
        self.assertTrue("1" in d2["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d2["2", 2])

    def testDoNotCollideEmptySet(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet2("pruebas0.dictset")
        d["1", 1] = set()
        d["2", 2] = set()

        del d
        d2 = DictSet2("pruebas0.dictset")
        d2["1", 1].add("1")
        d2["2", 2].add("2")
        self.assertTrue("1" in d2["1", 1])
        self.assertTrue("2" in d2["2", 2])

    def testAddRemove2(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet4("pruebas0.dictset")
        d["10"] = {1}
        d["20"] = {1, 2, 3}

        self.assertTrue(1 in d["10"])
        for i in range(1, 4):
            self.assertTrue(i in d["20"])

        d["20"].remove(2)
        self.assertRaises(Exception, d["20"].__contains__, 2)

        d["20"].add(2)
        self.assertTrue(2 in d["20"])<commit_msg>added doNotCollide with empty set<commit_after>import time
import os
import unittest

from hecuba import config
from hecuba import StorageDict


class DictSet(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str, k2:int>, s1:set<int, int>>
    '''

class DictSet2(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str, k2:int>, s1:set<str>>
    '''

class DictSet3(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str, k2:int>, s1:set<int>>
    '''

class DictSet4(StorageDict):
    '''
    @TypeSpec DictSet dict<<k1:str>, s1:set<int>>
    '''


class EmbeddedSetTest(unittest.TestCase):

    def testAddRemove(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet2("pruebas0.dictset")
        d["1", 1] = {"1"}
        d["2", 2] = {"1", "2", "3"}

        self.assertTrue("1" in d["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d["2", 2])

        d["2", 2].remove("2")
        self.assertRaises(Exception, d["2", 2].__contains__, "2")

        d["2", 2].add("2")
        self.assertTrue("2" in d["2", 2])
        self.assertEqual(1, len(d["1", 1]))
        self.assertEqual(3, len(d["2", 2]))

    def testDoNotCollide(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet2("pruebas0.dictset")
        d["1", 1] = {"1"}
        d["2", 2] = {"1", "2", "3"}

        self.assertTrue("1" in d["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d["2", 2])

        del d
        d2 = DictSet2("pruebas0.dictset")
        self.assertTrue("1" in d2["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d2["2", 2])

    def testDoNotCollideEmptySet(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet2("pruebas0.dictset")
        d["1", 1] = set()
        d["2", 2] = set()

        del d
        d2 = DictSet2("pruebas0.dictset")
<<<<<<< HEAD
        d2["1", 1].add("1")
        d2["2", 2].add("2")
        self.assertTrue("1" in d2["1", 1])
        self.assertTrue("2" in d2["2", 2])
=======
        d2["1", 1] = {"1"}
        d2["2", 2] = {"1", "2", "3"}
        self.assertTrue("1" in d2["1", 1])
        for i in range(1, 4):
            self.assertTrue(str(i) in d2["2", 2])
>>>>>>> ca9acda41812c232648df6224ed1fbac8f5c2b57

    def testAddRemove2(self):
        config.session.execute("DROP TABLE IF EXISTS pruebas0.dictset")
        d = DictSet4("pruebas0.dictset")
        d["10"] = {1}
        d["20"] = {1, 2, 3}

        self.assertTrue(1 in d["10"])
        for i in range(1, 4):
            self.assertTrue(i in d["20"])

        d["20"].remove(2)
        self.assertRaises(Exception, d["20"].__contains__, 2)

        d["20"].add(2)
        self.assertTrue(2 in d["20"])
{'fraction_non_alphanumeric': 0.19153716532484552, 'fraction_numerical': 0.05897771952817824, 'mean_word_length': 2.43979394719897, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, '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': '4326659', 'n_tokens_mistral': 2120, 'n_tokens_neox': 2016, 'n_words': 434}