Skip to content

Commit

Permalink
Fixed unittest to work with new add_nonland that takes a df
Browse files Browse the repository at this point in the history
  • Loading branch information
danyoungday committed Oct 7, 2024
1 parent 58b5e99 commit 2aac567
Showing 1 changed file with 6 additions and 27 deletions.
33 changes: 6 additions & 27 deletions use_cases/eluc/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import unittest
import pandas as pd

from app.components.lock import LockComponent
import app.constants as app_constants
from app import utils
from data import constants
Expand All @@ -14,40 +13,20 @@ class TestUtilFunctions(unittest.TestCase):
"""
Tests app utilities.
"""
def setUp(self):
self.lock_component = LockComponent()

def test_add_nonland(self):
"""
Simple vanilla test case for add_nonland(). Makes sure the nonland column added equals whatever we need left.
"""
data = [0, 0.01, 0.01, 0.2, 0.4, 0.02, 0.03, 0.01]
series = pd.Series(dict(zip(constants.LAND_USE_COLS, data)))
full = utils.add_nonland(series)
self.assertAlmostEqual(full["nonland"], 1 - sum(data), delta=app_constants.SLIDER_PRECISION)
df = pd.DataFrame([data], columns=constants.LAND_USE_COLS)
full = utils.add_nonland(df)
self.assertAlmostEqual(full["nonland"].iloc[0], 1 - sum(data), delta=app_constants.SLIDER_PRECISION)

def test_add_nonland_sum_over_one(self):
"""
Makes sure if the columns sum to >1, we get 0 for nonland
"""
data = [1 for _ in range(len(constants.LAND_USE_COLS))]
series = pd.Series(dict(zip(constants.LAND_USE_COLS, data)))
full = utils.add_nonland(series)
self.assertAlmostEqual(full["nonland"], 0, delta=app_constants.SLIDER_PRECISION)

def test_create_check_options_length(self):
"""
Makes sure the checklist we create has the same number of options as the input.
"""
values = ["a", "b", "c"]
options = self.lock_component.create_check_options(values)
self.assertEqual(len(options), len(values))

def test_create_check_options_values(self):
"""
Checks if the values in the options are correct
"""
values = ["a", "b", "c"]
options = self.lock_component.create_check_options(values)
for i, option in enumerate(options):
self.assertEqual(option["value"], values[i])
df = pd.DataFrame([data], columns=constants.LAND_USE_COLS)
full = utils.add_nonland(df)
self.assertAlmostEqual(full["nonland"].iloc[0], 0, delta=app_constants.SLIDER_PRECISION)

0 comments on commit 2aac567

Please sign in to comment.