Exemple #1
0
def test_givenCensusCSVFile_WhenSortedByArea_ShouldReturnSortedResult():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(CENSUS_CSV_FILE_PATH,
                                   STATE_CODE_CSV_FILE_PATH)
    sorted_json = census_analyser.sort_by_area()
    json_dict = json.loads(sorted_json)
    assert json_dict[0]["AreaInSqKm"] == 342239
Exemple #2
0
def test_givenCensusCSVFile_WhenSortedByPopulation_ShouldReturnSortedResult():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(CENSUS_CSV_FILE_PATH,
                                   STATE_CODE_CSV_FILE_PATH)
    sorted_json = census_analyser.sort_by_population()
    json_dict = json.loads(sorted_json)
    assert json_dict[0]["Population"] == 199812341
Exemple #3
0
def test_givenCensusCSVFile_WhenSortedByDensity_ShouldReturnSortedResult():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(CENSUS_CSV_FILE_PATH,
                                   STATE_CODE_CSV_FILE_PATH)
    sorted_json = census_analyser.sort_by_density()
    json_dict = json.loads(sorted_json)
    assert json_dict[0]["DensityPerSqKm"] == 1102
Exemple #4
0
def test_givenUSCensusCSVFile_WhenSortedByPopulation_ShouldReturnSortedResult(
):
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(US_CENSUS_CSV_FILE_PATH)
    sorted_json = census_analyser.sort_by_population()
    sorted_dict = json.loads(sorted_json)
    assert sorted_dict[0]["Population"] == 37253956
Exemple #5
0
def test_givenCensusCSVFile_WhenSortedByState_ShouldReturnSortedResult():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(CENSUS_CSV_FILE_PATH,
                                   STATE_CODE_CSV_FILE_PATH)
    sorted_json = census_analyser.sort_by_state()
    json_dict = json.loads(sorted_json)
    assert json_dict[0]["State"] == "Andhra Pradesh"
Exemple #6
0
def test_givenStateCodeCSVFile_WhenLoaded_ShouldReturnRecordsCount():
    census_analyser = CensusAnalyser()
    assert census_analyser.state_code_record_counter(
        CENSUS_CSV_FILE_PATH, STATE_CODE_CSV_FILE_PATH) == 29
Exemple #7
0
def test_givenIndiaCensusCSVFile_WhenHeadersWrong_ShouldRaiseException():
    census_analyser = CensusAnalyser()
    with pytest.raises(CensusAnalyserError):
        assert census_analyser.record_counter(STATE_CODE_CSV_FILE_PATH,
                                              CENSUS_CSV_FILE_PATH)
Exemple #8
0
def test_givenIndiaCensusCSVFile_WhenDelimiterWrong_ShouldRaiseException():
    census_analyser = CensusAnalyser()
    with pytest.raises(CensusAnalyserError):
        assert census_analyser.record_counter(
            CENSUS_CSV_FILE_WRONG_DELIMITER,
            STATE_CODE_CSV_FILE_WRONG_DELIMITER)
Exemple #9
0
def test_givenIndiaCensusCSVFile_WhenWrongFileType_ShouldRaiseException():
    census_analyser = CensusAnalyser()
    with pytest.raises(CensusAnalyserError):
        assert census_analyser.record_counter(CENSUS_CSV_FILE_WRONG_TYPE,
                                              STATE_CODE_CSV_FILE_WRONG_TYPE)
Exemple #10
0
def test_givenIndiaCensusCSVFile_WhenCounted_ShouldReturnRecordsCount():
    census_analyser = CensusAnalyser()
    assert census_analyser.record_counter(CENSUS_CSV_FILE_PATH,
                                          STATE_CODE_CSV_FILE_PATH) == 29
Exemple #11
0
def test_givenUSCensusCSVFile_WhenSorted_ShouldReturnStateWithMaxDensity():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(US_CENSUS_CSV_FILE_PATH)
    state = census_analyser.max_density_finder()
    assert state == "District of Columbia"
Exemple #12
0
def test_givenCensusCSVFile_WhenSorted_ShouldReturnStateWithMaxDensity():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(CENSUS_CSV_FILE_PATH,
                                   STATE_CODE_CSV_FILE_PATH)
    state = census_analyser.max_density_finder()
    assert state == "Bihar"
Exemple #13
0
def test_givenUSCensusCSVFile_WhenSortedByArea_ShouldReturnSortedResult():
    census_analyser = CensusAnalyser()
    census_analyser.record_counter(US_CENSUS_CSV_FILE_PATH)
    sorted_json = census_analyser.sort_by_area()
    json_dict = json.loads(sorted_json)
    assert json_dict[0]["Total area"] == 1723338.01
Exemple #14
0
def test_givenUSCensusCSVFile_WhenLoaded_ShouldReturnRecordCount():
    census_analyser = CensusAnalyser()
    assert census_analyser.record_counter(US_CENSUS_CSV_FILE_PATH) == 51