Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewTheTM committed Jun 9, 2022
1 parent 96f9d57 commit cc77101
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
33 changes: 33 additions & 0 deletions activitysim/examples/example_mwcog/test/configs/settings.yaml
@@ -0,0 +1,33 @@
inherit_settings: True

# EXAMPLE_HAS_WARNINGS
strict: False

# number of households to simulate
households_sample_size: 10
# simulate all households
# households_sample_size: 0

chunk_size: 0

# - shadow pricing global switches
# turn shadow_pricing on and off for all models (e.g. school and work)
# shadow pricing is deprecated for less than full samples
# see shadow_pricing.yaml for additional settings
use_shadow_pricing: False

# turn writing of sample_tables on and off for all models
# (if True, tables will be written if DEST_CHOICE_SAMPLE_TABLE_NAME is specified in individual model settings)
want_dest_choice_sample_tables: False

# global switch to turn on or off presampling of destination alternatives at TAZ level (multizone models only)
want_dest_choice_presampling: True

# - tracing
# trace household id; comment out or leave empty for no trace
trace_hh_id:

# trace origin, destination in accessibility calculation; comment out or leave empty for no trace
# trace_od: [5, 11]
trace_od:

7 changes: 7 additions & 0 deletions activitysim/examples/example_mwcog/test/output/.gitignore
@@ -0,0 +1,7 @@
*.csv
*.log
*.prof
*.h5
*.txt
*.yaml
*.omx
@@ -0,0 +1,2 @@
*.mmap
*.feather
@@ -0,0 +1,3 @@
*.csv
*.log
*.txt
50 changes: 50 additions & 0 deletions activitysim/examples/example_mwcog/test/regress/final_trips.csv
@@ -0,0 +1,50 @@
trip_id,person_id,household_id,primary_purpose,trip_num,outbound,trip_count,destination,origin,tour_id,purpose,destination_logsum,depart,trip_mode,mode_choice_logsum
52153233,159003,1590,school,1,True,1,27,25,6519154,school,,11,WALK,3.3669236886282277
52153237,159003,1590,school,1,False,1,25,27,6519154,home,,27,WALK,3.486923685946018
52153889,159005,1590,school,1,True,1,27,25,6519236,school,,7,WALK,3.3669236886282277
52153893,159005,1590,school,1,False,1,25,27,6519236,home,,27,WALK,3.486923685946018
52154545,159007,1590,school,1,True,1,19,25,6519318,school,,11,WALK,3.1673109534958903
52154549,159007,1590,school,1,False,1,25,19,6519318,home,,27,WALK,3.1673109534958903
53136529,162001,1620,othdiscr,1,True,1,25,25,6642066,othdiscr,,13,WALK,2.0354872001527298
53136533,162001,1620,othdiscr,1,False,1,25,25,6642066,home,,17,WALK,2.0354872001527298
53136593,162001,1620,shopping,1,True,1,24,25,6642074,shopping,,20,WALK,0.5873669693786134
53136597,162001,1620,shopping,1,False,1,25,24,6642074,home,,23,WALK,0.5873669693786134
53136689,162002,1620,atwork,1,True,1,38,38,6642086,atwork,,22,WALK,-0.611999989181757
53136693,162002,1620,atwork,1,False,1,38,38,6642086,work,,23,WALK,-0.611999989181757
53136969,162002,1620,work,1,True,1,38,25,6642121,work,,15,KNR_MR,-0.8976646759623489
53136973,162002,1620,work,1,False,1,25,38,6642121,home,,38,KNR_MR,-0.8795523663195886
53137017,162003,1620,atwork,1,True,1,40,26,6642127,atwork,,19,WALK,0.8548156977447776
53137021,162003,1620,atwork,1,False,1,26,40,6642127,work,,19,WALK,0.8548156977447776
53137297,162003,1620,work,1,True,1,26,25,6642162,work,,13,WALK,-0.16346785221758944
53137301,162003,1620,work,1,False,1,25,26,6642162,home,,30,WALK,-0.16346785221758944
53530241,163201,1632,work,1,True,1,24,25,6691280,work,,9,PNR_MR,-0.4392097253621265
53530245,163201,1632,work,1,False,1,25,24,6691280,home,,33,PNR_MR,-0.2591827350249029
53530329,163202,1632,escort,1,True,1,39,25,6691291,escort,,28,DRIVEALONE,-0.06197964360005489
53530333,163202,1632,escort,1,False,1,25,39,6691291,home,,29,SHARED2,-0.1701462043767353
53530337,163202,1632,escort,1,True,1,23,25,6691292,escort,,24,WALK,-0.92999997921288
53530341,163202,1632,escort,1,False,1,25,23,6691292,home,,25,WALK,-0.92999997921288
53530849,163203,1632,shopping,1,True,1,22,25,6691356,shopping,,19,WALK,-1.409999968484044
53530853,163203,1632,shopping,1,False,1,25,22,6691356,home,,20,WALK,-1.289999971166253
278275841,848401,8484,work,1,True,1,1,42,34784480,work,,16,DRIVEALONE,-0.3047444691565592
278275845,848401,8484,work,1,False,1,42,1,34784480,home,,30,DRIVEALONE,-0.3737130471632631
381661281,1163601,11636,shopping,1,True,1,25,47,47707660,shopping,,39,SHARED2,0.13405080458662966
381661285,1163601,11636,shopping,1,False,2,37,25,47707660,shopping,12.938418648448124,40,SHARED2,-0.19334951027125485
381661286,1163601,11636,shopping,2,False,2,47,37,47707660,home,,40,SHARED2,0.11558833086308477
381661441,1163601,11636,work,1,True,1,55,47,47707680,work,,14,DRIVEALONE,-0.2776450324248023
381661445,1163601,11636,work,1,False,3,49,55,47707680,shopping,8.755660261900594,37,DRIVEALONE,-1.318377909968898
381661446,1163601,11636,work,2,False,3,26,49,47707680,shopping,11.445671730580356,37,DRIVEALONE,-0.628015657476555
381661447,1163601,11636,work,3,False,3,47,26,47707680,home,,38,DRIVEALONE,-1.096460443761022
381661769,1163602,11636,work,1,True,1,40,47,47707721,work,,11,PNR_AB,-0.2324912003637291
381661773,1163602,11636,work,1,False,1,47,40,47707721,home,,24,PNR_AB,-0.24617547380648477
415969977,1268201,12682,eatout,1,True,1,39,47,51996247,eatout,,19,WALK,-1.3714739979449653
415969981,1268201,12682,eatout,1,False,1,47,39,51996247,home,,21,WALK,-1.3714739979449653
415970241,1268201,12682,work,1,True,1,12,47,51996280,work,,6,DRIVEALONE,-0.3338142112103269
415970245,1268201,12682,work,1,False,1,47,12,51996280,home,,15,DRIVEALONE,-0.339542247430106
468417329,1428101,14281,othdiscr,1,True,2,44,49,58552166,escort,13.862092230717861,25,WALK,2.83170898894978
468417330,1428101,14281,othdiscr,2,True,2,38,44,58552166,othdiscr,,26,WALK,-0.689999984577298
468417333,1428101,14281,othdiscr,1,False,4,54,38,58552166,shopping,16.463054848061834,25,WALK,-1.409999968484044
468417334,1428101,14281,othdiscr,2,False,4,54,54,58552166,othdiscr,26.955410749877714,26,WALK,4.63959178556302
468417335,1428101,14281,othdiscr,3,False,4,45,54,58552166,othmaint,26.28617562432176,26,WALK,4.039591798974065
468417336,1428101,14281,othdiscr,4,False,4,49,45,58552166,home,,28,WALK,2.895014407185858
650752641,1984001,19840,work,1,True,1,28,57,81344080,work,,9,WALK,0.21761578208744412
650752645,1984001,19840,work,1,False,1,57,28,81344080,home,,13,WALK_MR,0.22380439703983218
48 changes: 48 additions & 0 deletions activitysim/examples/example_mwcog/test/test_mwcog.py
@@ -0,0 +1,48 @@
# ActivitySim
# See full license in LICENSE.txt.
import os
import subprocess
import pkg_resources

import pandas as pd
import pandas.testing as pdt

from activitysim.core import inject


def teardown_function(func):
inject.clear_cache()
inject.reinject_decorated_tables()


def test_mwcog():

def example_path(dirname):
resource = os.path.join('examples', 'example_mwcog', dirname)
return pkg_resources.resource_filename('activitysim', resource)

def test_path(dirname):
return os.path.join(os.path.dirname(__file__), dirname)

def regress():
regress_trips_df = pd.read_csv(test_path('regress/final_trips.csv'))
final_trips_df = pd.read_csv(test_path('output/final_trips.csv'))

# person_id,household_id,tour_id,primary_purpose,trip_num,outbound,trip_count,purpose,
# destination,origin,destination_logsum,depart,trip_mode,mode_choice_logsum
# compare_cols = []
pdt.assert_frame_equal(final_trips_df, regress_trips_df)

file_path = os.path.join(os.path.dirname(__file__), '../simulation.py')

subprocess.run(['coverage', 'run', '-a', file_path,
'-c', test_path('configs'), '-c', example_path('configs'),
'-d', example_path('data'),
'-o', test_path('output')], check=True)

regress()


if __name__ == '__main__':

test_mwcog()

0 comments on commit cc77101

Please sign in to comment.