Esempio n. 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);
  }
Esempio n. 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);
  }
Esempio n. 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);
  }
Esempio n. 4
0
  @Test
  public void testFilterByAge18And65() throws IOException {
    List<Person> people = PeopleData.read("people.csv");
    List<Person> selected =
        PersonFilter.search(people, person -> person.getAge() > 18 && person.getAge() < 65);

    for (int i = 0; i < selected.size() - 1; i++) {
      if (selected.get(i).getAge() <= 18 || selected.get(i).getAge() >= 65)
        fail("Filter by age between 18 and 65 : index " + i);
    }
    System.out.println("Total people between 18 and 65: " + selected.size() + "/" + people.size());
  }