Пример #1
0
  @Test
  public void testFilterByCity() throws IOException {
    List<Person> people = PeopleData.read("people.csv");
    List<Person> selected = PersonFilter.search(people, person -> person.getCity().equals("Zug"));

    for (int i = 0; i < selected.size() - 1; i++) {
      if (!selected.get(i).getCity().equals("Zug")) fail("Filter by city : index " + i);
    }
    System.out.println("Total people from Zug: " + selected.size() + "/" + people.size());
    PeopleData.write("output/filteredByCity.csv", selected);
  }
Пример #2
0
  @Test
  public void testFilterByMale() throws IOException {
    List<Person> people = PeopleData.read("people.csv");
    List<Person> selected = PersonFilter.search(people, this::isMale);

    for (int i = 0; i < selected.size() - 1; i++) {
      if (selected.get(i).getGender() != Gender.MALE) fail("Filter male people : index " + i);
    }
    System.out.println("Total male people: " + selected.size() + "/" + people.size());
    PeopleData.write("output/filteredByGenderMale.csv", selected);
  }
Пример #3
0
  @Test
  public void testFilterByMaleZurich() throws IOException {
    List<Person> people = PeopleData.read("people.csv");
    List<Person> selected =
        PersonFilter.search(
            people,
            person -> person.getGender() == Gender.MALE && person.getCity().equals("Zürich"));

    for (int i = 0; i < selected.size() - 1; i++) {
      if (selected.get(i).getGender() != Gender.MALE && selected.get(i).getCity().equals("Zürich"))
        fail("Filter male people from zurich: index " + i);
    }
    System.out.println("Total male people from zurich: " + selected.size() + "/" + people.size());
    PeopleData.write("output/filteredByMaleZH.csv", selected);
  }