<commit_before>import unittest
import pysal
from pysal.esda import moran
import numpy as np


class Moran_Tester(unittest.TestCase):
    def setUp(self):
        self.w=pysal.open("../../examples/stl.gal").read()
        f=pysal.open("../../examples/stl_hom.txt")
        self.y=np.array(f.by_col['HR8893'])
    def test_moran(self):
        mi=moran.Moran(self.y,self.w)
        self.assertAlmostEquals(mi.I,0.24365582621771659,7)
        self.assertAlmostEquals(mi.p_norm, 0.00027147862770937614)
    def test_sids(self):
        w=pysal.open("../../examples/sids2.gal").read()
        f=pysal.open("../../examples/sids2.dbf")
        SIDR=np.array(f.by_col("SIDR74"))
        mi=pysal.Moran(SIDR,w)
        self.assertAlmostEquals(mi.I,0.24772519320480135)
        self.assertAlmostEquals(mi.p_norm,0.00011583330781)

class Moran_BV_matrix_Tester(unittest.TestCase):
    def setUp(self):
        f=pysal.open("../../examples/sids2.dbf")
        varnames=['SIDR74','SIDR79','NWR74','NWR79']
        self.names=varnames
        vars=[np.array(f.by_col[var]) for var in varnames]
        self.vars=vars
        self.w=pysal.open("../../examples/sids2.gal").read()
    def test_Moran_BV_matrix(self):
        res=moran.Moran_BV_matrix(self.vars,self.w,varnames=self.names)
        self.assertAlmostEquals(res[(0,1)].I,0.19362610652874668)
        self.assertAlmostEquals(res[(3,0)].I,0.37701382542927858)
        
class Moran_Local_Tester(unittest.TestCase):
    def setUp(self):
        np.random.seed(10)
        self.w = pysal.open("../../examples/desmith.gal").read()
        f = pysal.open("../../examples/desmith.txt")
        self.y = np.array(f.by_col['z'])
    def test_Moran_Local(self):
        lm = moran.Moran_Local(self.y, self.w, transformation="r", permutations=99)
        self.assertAlmostEquals(lm.z_sim[0], -0.01207411940840397 )
        self.assertAlmostEquals(lm.p_z_sim[0], 0.99036648060872201 )
        self.assertAlmostEquals(lm.VI_sim, 0.23519675087018393 )
        



suite = unittest.TestSuite()
test_classes = [Moran_Tester,Moran_BV_matrix_Tester, Moran_Local_Tester ]
for i in test_classes:
    a = unittest.TestLoader().loadTestsFromTestCase(i)
    suite.addTest(a)

if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite)

<commit_msg>- fixing test to reflect new conditional randomization<commit_after>import unittest
import pysal
from pysal.esda import moran
import numpy as np


class Moran_Tester(unittest.TestCase):
    def setUp(self):
        self.w=pysal.open("../../examples/stl.gal").read()
        f=pysal.open("../../examples/stl_hom.txt")
        self.y=np.array(f.by_col['HR8893'])
    def test_moran(self):
        mi=moran.Moran(self.y,self.w)
        self.assertAlmostEquals(mi.I,0.24365582621771659,7)
        self.assertAlmostEquals(mi.p_norm, 0.00027147862770937614)
    def test_sids(self):
        w=pysal.open("../../examples/sids2.gal").read()
        f=pysal.open("../../examples/sids2.dbf")
        SIDR=np.array(f.by_col("SIDR74"))
        mi=pysal.Moran(SIDR,w)
        self.assertAlmostEquals(mi.I,0.24772519320480135)
        self.assertAlmostEquals(mi.p_norm,0.00011583330781)

class Moran_BV_matrix_Tester(unittest.TestCase):
    def setUp(self):
        f=pysal.open("../../examples/sids2.dbf")
        varnames=['SIDR74','SIDR79','NWR74','NWR79']
        self.names=varnames
        vars=[np.array(f.by_col[var]) for var in varnames]
        self.vars=vars
        self.w=pysal.open("../../examples/sids2.gal").read()
    def test_Moran_BV_matrix(self):
        res=moran.Moran_BV_matrix(self.vars,self.w,varnames=self.names)
        self.assertAlmostEquals(res[(0,1)].I,0.19362610652874668)
        self.assertAlmostEquals(res[(3,0)].I,0.37701382542927858)
        
class Moran_Local_Tester(unittest.TestCase):
    def setUp(self):
        np.random.seed(10)
        self.w = pysal.open("../../examples/desmith.gal").read()
        f = pysal.open("../../examples/desmith.txt")
        self.y = np.array(f.by_col['z'])
    def test_Moran_Local(self):
        lm = moran.Moran_Local(self.y, self.w, transformation="r", permutations=99)
        self.assertAlmostEquals(lm.z_sim[0],-0.081383956359666748 )
        self.assertAlmostEquals(lm.p_z_sim[0], 0.93513660775432128 )
        self.assertAlmostEquals(lm.VI_sim,  0.2067126047680822 )
        



suite = unittest.TestSuite()
test_classes = [Moran_Tester,Moran_BV_matrix_Tester, Moran_Local_Tester ]
for i in test_classes:
    a = unittest.TestLoader().loadTestsFromTestCase(i)
    suite.addTest(a)

if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite)


{'fraction_non_alphanumeric': 0.155852554429834, 'fraction_numerical': 0.08234533304591507, 'mean_word_length': 3.1764176417641763, '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': '7196391', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1734, 'n_words': 194}