adds fixtures and tests
This commit is contained in:
parent
ce4cc637ae
commit
b71152a884
1
src/py/crankshaft/test/fixtures/getis.json
vendored
Normal file
1
src/py/crankshaft/test/fixtures/getis.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
[[0.43099999999999999, -0.4491160909028587, 0.32667395669425392], [0.021999999999999999, -0.93788225530474956, 0.17415246162388542], [0.44600000000000001, -0.4491160909028587, 0.32667395669425392], [0.216, -0.64751176059715954, 0.25865039275726565], [0.11700000000000001, -0.96347562762330119, 0.1676544447116961], [0.049000000000000002, -0.20152426147617952, 0.42014433032225806], [0.072999999999999995, -0.46619525535633877, 0.32053787260380839], [0.16300000000000001, -0.74976349152754251, 0.22669858024734424], [0.052999999999999999, -0.64751176059715954, 0.25865039275726565], [0.156, -0.56083197633324544, 0.28745604294545346], [0.29599999999999999, -0.24280805846929457, 0.40407704630238783], [0.29099999999999998, -0.26928692847374969, 0.39385444517601476], [0.44, -0.67722330498207772, 0.24913214171492104], [0.16500000000000001, -0.011684382726338413, 0.49533871177388633], [0.378, -0.56473075182761978, 0.28612845711175672], [0.042999999999999997, -0.99072103490325258, 0.1609109084310375], [0.45600000000000002, -0.28743876271061125, 0.38688819224593796], [0.156, 0.13295980219309725, 0.4471125856868039], [0.19500000000000001, 0.0063207047268819955, 0.49747842043259183], [0.0070000000000000001, -1.0415760797098768, 0.1488041317793396], [0.111, -0.36942477246818262, 0.35590556804466089], [0.22500000000000001, 0.17506551624725114, 0.43051407691606425], [0.26900000000000002, -0.44363455341924385, 0.32865340985373048], [0.33800000000000002, -0.43284736233536597, 0.33256283131987785], [0.189, -0.60291193010388022, 0.27328363953070622], [0.20799999999999999, 0.035856268747985663, 0.48569848295465989], [0.123, 0.089678570182411793, 0.4642713229152271], [0.0030000000000000001, -1.1057224660076166, 0.13442333147768415], [0.16800000000000001, 0.11677761660057258, 0.45351814086906583], [0.29999999999999999, -0.013808110669475293, 0.49449153588626749], [0.378, -0.23290337417697893, 0.40791821913691739], [0.41699999999999998, 0.22945579816510672, 0.40925733604961323], [0.002, 6.5207630666532674, 3.4975355944766306e-11], [0.46200000000000002, -0.14672827921301743, 0.44167324829783083], [0.126, 0.22908126100922532, 0.40940287888500482], [0.047, -1.0840432095769956, 0.13917282042962942], [0.017000000000000001, 4.0493273511601489, 2.5682527508119612e-05], [0.067000000000000004, -0.93058949009641589, 0.17603297655968531], [0.435, -0.39105578866749485, 0.34787799959221344], [0.0030000000000000001, 6.4632623511010854, 5.1234683162704187e-11], [0.098000000000000004, 0.29440403358766087, 0.38422459253128149], [0.38400000000000001, -0.42044605311189681, 0.33707981556243372], [0.38700000000000001, 0.056785871984068648, 0.47735788415038005], [0.36899999999999999, -0.15875022725747437, 0.43693283214176271], [0.20399999999999999, 0.14086541129997771, 0.44398813370614665], [0.014, 6.0345506436163996, 7.9702822119998018e-10], [0.13400000000000001, -0.85883340027064359, 0.19521621870003536], [0.14499999999999999, -0.93901580426004294, 0.17386131505073421], [0.029000000000000001, 2.052209368389633, 0.020074659704574338], [0.45300000000000001, -0.2873860843780221, 0.38690835753455055], [0.27200000000000002, 0.11238736962962483, 0.45525813472736054], [0.47599999999999998, -0.22667990193583551, 0.41033632813474463], [0.060999999999999999, -0.66318887096788159, 0.25360479911357758], [0.47599999999999998, -0.41451366242647014, 0.33924898169485895], [0.14499999999999999, -0.65907426867863195, 0.25492403906163263], [0.127, -0.56550838435631712, 0.28586401153505392], [0.311, -0.019571757025783815, 0.49219249707263191], [0.27700000000000002, -0.049735022936677371, 0.48016677335804769], [0.20899999999999999, 0.34564692985400752, 0.36480403618322277], [0.26200000000000001, -0.055301366746933138, 0.47794918666392716], [0.315, -0.11227385176628404, 0.45530313698210811], [0.39900000000000002, -0.23091105262392728, 0.4086919520030482], [0.38, -0.05314541432928175, 0.47880802357740249], [0.29499999999999998, -0.048726126739086051, 0.48056877723722968], [0.29999999999999999, -0.65725648028245498, 0.25550800720533962], [0.35499999999999998, -0.29942829331962884, 0.38230663846055501], [0.39000000000000001, -0.38409317960223854, 0.35045469320011735], [0.249, -0.52740757430541685, 0.29895529238584306], [0.246, 0.34740441796104815, 0.36414375737078841], [0.089999999999999997, 0.47786308046182885, 0.31637383012047438], [0.23400000000000001, 0.0047163311140149293, 0.49811846308566454], [0.307, -0.098930796747205507, 0.46059660828759452], [0.40500000000000003, -0.37158786444006753, 0.35509986295795459], [0.45800000000000002, 0.60261000309518942, 0.27338408212548115], [0.44600000000000001, 0.046168582994860159, 0.48158794144995187], [0.28499999999999998, -0.049232649167827866, 0.48036694626611731], [0.050000000000000003, 1.0035582996961303, 0.15779578142846606], [0.218, 0.52664582141189142, 0.29921978282283035]]
|
1
src/py/crankshaft/test/fixtures/neighbors_getis.json
vendored
Normal file
1
src/py/crankshaft/test/fixtures/neighbors_getis.json
vendored
Normal file
File diff suppressed because one or more lines are too long
38
src/py/crankshaft/test/test_clustering_getis.py
Normal file
38
src/py/crankshaft/test/test_clustering_getis.py
Normal file
@ -0,0 +1,38 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
|
||||
|
||||
# from mock_plpy import MockPlPy
|
||||
# plpy = MockPlPy()
|
||||
#
|
||||
# import sys
|
||||
# sys.modules['plpy'] = plpy
|
||||
from helper import plpy, fixture_file
|
||||
|
||||
import crankshaft.clustering as cc
|
||||
import crankshaft.pysal_utils as pu
|
||||
from crankshaft import random_seeds
|
||||
import json
|
||||
|
||||
class GetisTest(unittest.TestCase):
|
||||
"""Testing class for Getis-Ord's G funtion"""
|
||||
|
||||
def setUp(self):
|
||||
plpy._reset()
|
||||
print(help(cc))
|
||||
self.neighbors_data = json.loads(open(fixture_file('neighbors_getis.json')).read())
|
||||
self.getis_data = json.loads(open(fixture_file('getis.json')).read())
|
||||
|
||||
def test_getis_ord(self):
|
||||
"""Test Getis-Ord's G*"""
|
||||
data = [ { 'id': d['id'],
|
||||
'attr1': d['hr8893'],
|
||||
'neighbors': d['neighbors'] } for d in self.neighbors_data]
|
||||
plpy._define_result('select', data)
|
||||
random_seeds.set_random_seeds(1234)
|
||||
result = cc.getis_ord('subquery', 'value', 'knn', 5, 99, 'the_geom', 'cartodb_id')
|
||||
result = [(row[0], row[1]) for row in result]
|
||||
expected = self.getis_data
|
||||
for ([res_z, res_p], [exp_z, exp_p]) in zip(result, expected):
|
||||
self.assertAlmostEqual(res_val, exp_val)
|
||||
self.assertEqual(res_quad, exp_quad)
|
Loading…
Reference in New Issue
Block a user