From 887cc058625bf2f489e646acf36c7a9edf5c945f Mon Sep 17 00:00:00 2001 From: Nathan Date: Sat, 24 Jul 2021 20:31:17 -0400 Subject: [PATCH] passed all tests --- .idea/.gitignore | 3 + .idea/compiler.xml | 16 ++++ .idea/encodings.xml | 6 ++ .idea/jarRepositories.xml | 20 +++++ .idea/libraries/Maven__junit_junit_4_12.xml | 13 +++ .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 +++ .idea/misc.xml | 11 +++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ interfaces-1.iml | 16 ++++ pom.xml | 12 +++ .../java/io/zipcoder/interfaces/Educator.java | 35 ++++++++ .../io/zipcoder/interfaces/Instructor.java | 37 ++++++++ .../io/zipcoder/interfaces/Instructors.java | 20 +++++ .../java/io/zipcoder/interfaces/Learner.java | 6 ++ .../java/io/zipcoder/interfaces/People.java | 86 +++++++++++++++++++ .../java/io/zipcoder/interfaces/Person.java | 19 ++++ .../java/io/zipcoder/interfaces/Student.java | 26 ++++++ .../java/io/zipcoder/interfaces/Students.java | 24 ++++++ .../java/io/zipcoder/interfaces/Teacher.java | 24 ++++++ .../interfaces/ZipCodeWilmington.java | 50 +++++++++++ .../io/zipcoder/interfaces/EducatorTest.java | 73 ++++++++++++++++ .../zipcoder/interfaces/InstructorSTest.java | 18 ++++ .../zipcoder/interfaces/InstructorTest.java | 63 ++++++++++++++ .../io/zipcoder/interfaces/PeopleTest.java | 57 ++++++++++++ .../io/zipcoder/interfaces/StudentSTest.java | 32 +++++++ .../io/zipcoder/interfaces/StudentTest.java | 37 ++++++++ .../io/zipcoder/interfaces/TestPerson.java | 25 ++++++ .../interfaces/ZipCodeWilmingtonTest.java | 39 +++++++++ 29 files changed, 795 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 interfaces-1.iml create mode 100644 src/main/java/io/zipcoder/interfaces/Educator.java create mode 100644 src/main/java/io/zipcoder/interfaces/Instructor.java create mode 100644 src/main/java/io/zipcoder/interfaces/Instructors.java create mode 100644 src/main/java/io/zipcoder/interfaces/Learner.java create mode 100644 src/main/java/io/zipcoder/interfaces/People.java create mode 100644 src/main/java/io/zipcoder/interfaces/Student.java create mode 100644 src/main/java/io/zipcoder/interfaces/Students.java create mode 100644 src/main/java/io/zipcoder/interfaces/Teacher.java create mode 100644 src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java create mode 100644 src/test/java/io/zipcoder/interfaces/EducatorTest.java create mode 100644 src/test/java/io/zipcoder/interfaces/InstructorSTest.java create mode 100644 src/test/java/io/zipcoder/interfaces/InstructorTest.java create mode 100644 src/test/java/io/zipcoder/interfaces/PeopleTest.java create mode 100644 src/test/java/io/zipcoder/interfaces/StudentSTest.java create mode 100644 src/test/java/io/zipcoder/interfaces/StudentTest.java create mode 100644 src/test/java/io/zipcoder/interfaces/ZipCodeWilmingtonTest.java diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..325625e7 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..63e90019 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 00000000..712ab9d9 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 00000000..d4110417 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 00000000..f58bbc11 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..17e19eb4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..711b3a53 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/interfaces-1.iml b/interfaces-1.iml new file mode 100644 index 00000000..3c40a7ee --- /dev/null +++ b/interfaces-1.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f0effe12..65b44a67 100644 --- a/pom.xml +++ b/pom.xml @@ -5,6 +5,18 @@ io.zipcoder interfaces-1 0.0.1-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + + + jar interfaces-1 diff --git a/src/main/java/io/zipcoder/interfaces/Educator.java b/src/main/java/io/zipcoder/interfaces/Educator.java new file mode 100644 index 00000000..8879b104 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Educator.java @@ -0,0 +1,35 @@ +package io.zipcoder.interfaces; + +public enum Educator implements Teacher { + LEON (new Instructor(0, "Leon")), + DOLIO(new Instructor(1,"Dolio")), + KRIS(new Instructor(2,"Kris")); + + private final Instructor instructor; + private Double timeWorked; + + Educator(Instructor instructor) { + this.instructor = instructor; + Instructors.getInstance().add(instructor); + } + + @Override + public void teach(Learner learner, Double numberOfHours) { + instructor.teach(learner,numberOfHours); + setTimeWorked(numberOfHours); + } + + @Override + public void lecture(Learner[] learners, Double numberOfHours) { + instructor.lecture(learners,numberOfHours); + setTimeWorked(numberOfHours); + } + + public void setTimeWorked(Double timeWorked) { + this.timeWorked = timeWorked; + } + + public Double getTimeWorked() { + return timeWorked; + } +} diff --git a/src/main/java/io/zipcoder/interfaces/Instructor.java b/src/main/java/io/zipcoder/interfaces/Instructor.java new file mode 100644 index 00000000..f2c414b1 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Instructor.java @@ -0,0 +1,37 @@ +package io.zipcoder.interfaces; + +/** + * Create an Instructor class such that: + * Instructor is a subclass of Person + * Instructor implements the Teacher interface + * + * Instructor should have a concrete implementation of the teach method + * which invokes the learn method on the specified Learner object. + * + * Instructor should have a concrete implementation of the lecture method + * which invokes the learn method on each of the elements in the specified array of Learner objects. + * + * numberOfHours should be evenly split amongst the learners. + * double numberOfHoursPerLearner = numberOfHours / learners.length; + */ + +public class Instructor extends Person implements Teacher { + + public Instructor(long id, String name) { + super(id, name); + } + + + @Override + public void teach(Learner learner, Double numberOfHours) { + learner.learn(numberOfHours); + } + + @Override + public void lecture(Learner[] learners, Double numberOfHours) { + Double numberOfHoursPerLearner = numberOfHours/ learners.length; + for(Learner learner: learners){ + learner.learn(numberOfHoursPerLearner); + } + } +} diff --git a/src/main/java/io/zipcoder/interfaces/Instructors.java b/src/main/java/io/zipcoder/interfaces/Instructors.java new file mode 100644 index 00000000..01f3cdd7 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Instructors.java @@ -0,0 +1,20 @@ +package io.zipcoder.interfaces; + +import java.util.Arrays; + +public final class Instructors extends People { + private final static Instructors INSTANCE = new Instructors(); + private Instructors(){ + Instructor leon = new Instructor(0,"Leon"); + Instructor dolio = new Instructor(1,"Dolio"); + Instructor kris = new Instructor(2, "Kris"); + Arrays.asList(leon, dolio, kris).forEach(this::add); + } + + @Override + public Instructor[] toArray() { + return INSTANCE.getPersonList().toArray(new Instructor[0]); + } + + public static Instructors getInstance(){return INSTANCE;} +} diff --git a/src/main/java/io/zipcoder/interfaces/Learner.java b/src/main/java/io/zipcoder/interfaces/Learner.java new file mode 100644 index 00000000..678bf5c3 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Learner.java @@ -0,0 +1,6 @@ +package io.zipcoder.interfaces; + +public interface Learner { + void learn(Double numberOfHours); + Double getTotalStudyTime(); +} diff --git a/src/main/java/io/zipcoder/interfaces/People.java b/src/main/java/io/zipcoder/interfaces/People.java new file mode 100644 index 00000000..ea44c0d5 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/People.java @@ -0,0 +1,86 @@ +package io.zipcoder.interfaces; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * Create a People class. + * The class should instantiate a List field of Person objects named personList. + * The class should define a method named add which adds a Person to the personList. + * The class should define a method named findById which makes use of a long id parameter + * to return a Person object with the respective id field. + * The class should define a method named contains which makes use of a Person person parameter to + * return true if the personList contains the respective Person object. + * The class should define a method named remove which makes use of a Person person parameter + * to remove a respective Person object. + * The class should define a method named remove which makes use of a long id parameter to + * remove a Person object with the respective id field. + * The class should define a named removeAll which clears our personList field. + * The class should define a method named count which returns the size of personList. + * The class should define a method named toArray which returns an array representation of the + * personList field. + * + * The class should implement Iterable and define a method named iterator which makes use of + * the personList field to generate a new a Iterator. + * + */ +public abstract class People implements Iterable { + private List personList; + + public People() { + this.personList = new ArrayList(); + } + + public void add(PersonType person){ + personList.add(person); + } + + public PersonType findById(long id){ + for(PersonType person:personList){ + if(person.getId() == id){ + return person; + } + } + return null; + } + + public boolean contains(PersonType person){ + if(personList.contains(person)){ + return true; + } + return false; + } + + //Should only remove - not return a string + public void removePerson(PersonType person){ + if(personList.contains(person)){ + personList.remove(person); + } else { + throw new UnsupportedOperationException("That person is not here"); + } + } + + public void removeById(long id){ + personList.removeIf(person -> person.getId() == id); + } + + public void removeAll(){ + personList.clear(); + } + + public Integer count(){ + return personList.size(); + } + + public abstract PersonType[] toArray(); + + @Override + public Iterator iterator() { + return personList.iterator(); + } + + public List getPersonList() { + return personList; + } +} diff --git a/src/main/java/io/zipcoder/interfaces/Person.java b/src/main/java/io/zipcoder/interfaces/Person.java index fc6a3ffe..cb33503c 100644 --- a/src/main/java/io/zipcoder/interfaces/Person.java +++ b/src/main/java/io/zipcoder/interfaces/Person.java @@ -2,4 +2,23 @@ public class Person { + private final long id; + private String name; + + public Person(long id, String name) { + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/src/main/java/io/zipcoder/interfaces/Student.java b/src/main/java/io/zipcoder/interfaces/Student.java new file mode 100644 index 00000000..0be50d9a --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Student.java @@ -0,0 +1,26 @@ +package io.zipcoder.interfaces; + +public class Student extends Person implements Learner{ + private long id; + private String name; + private Double totalStudyTime; + + public Student(long id, String name) { + super(id, name); + } + + public Student() { + super(0,""); + } + + @Override + public void learn(Double numberOfHours) { + this.totalStudyTime = numberOfHours; + } + + @Override + public Double getTotalStudyTime() { + return this.totalStudyTime; + } + +} diff --git a/src/main/java/io/zipcoder/interfaces/Students.java b/src/main/java/io/zipcoder/interfaces/Students.java new file mode 100644 index 00000000..ddde6b61 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Students.java @@ -0,0 +1,24 @@ +package io.zipcoder.interfaces; + +import java.util.Arrays; + +public final class Students extends People { + private final static Students INSTANCE = new Students(); + private Students(){ + Student nate = new Student(0,"Nate"); + Student zach = new Student(1,"Zach"); + Student jeremy = new Student(2,"Jeremy"); + Student jen = new Student(3, "Jen"); + Arrays.asList(nate,zach,jeremy,jen) + .forEach(student -> add(student)); + } + + @Override + public Student[] toArray() { + return INSTANCE.getPersonList().toArray(new Student[0]); + } + + public static Students getInstance(){return INSTANCE;} + + +} diff --git a/src/main/java/io/zipcoder/interfaces/Teacher.java b/src/main/java/io/zipcoder/interfaces/Teacher.java new file mode 100644 index 00000000..3c6cfe41 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/Teacher.java @@ -0,0 +1,24 @@ +package io.zipcoder.interfaces; + +/** + * Create a Teacher interface. + * + * Teacher should declare a teach method signature: + * Method name: teach + * Method parameters: + * Learner learner + * double numberOfHours + * Method return-type: void + * + * Teacher should declare a lecture method signature: + * Method name: lecture + * Method parameters: + * Learner[] learners + * double numberOfHours + * Method return-type: void + */ + +public interface Teacher { + void teach(Learner learner, Double numberOfHours); + void lecture(Learner[] learners,Double numberOfHours); +} diff --git a/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java new file mode 100644 index 00000000..7cf8aa46 --- /dev/null +++ b/src/main/java/io/zipcoder/interfaces/ZipCodeWilmington.java @@ -0,0 +1,50 @@ +package io.zipcoder.interfaces; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.stream.Stream; + +public class ZipCodeWilmington { + private static final ZipCodeWilmington INSTANCE = new ZipCodeWilmington(); + private static final Students students = Students.getInstance(); + private static final Instructors instructors = Instructors.getInstance(); + + private ZipCodeWilmington() { + } + + public static ZipCodeWilmington getInstance(){ + return INSTANCE; + } + + public void hostLecture(Teacher teacher, Double numberOfHours){ + teacher.lecture(students.toArray(), numberOfHours); + } + + public void hostLecture(long id, Double numberOfHours){ + Teacher teacher = instructors.findById(id); + hostLecture(teacher,numberOfHours); + } + + public static Map getStudyMap(){ + Map studyMap = new HashMap<>(); +// Stream +// .of(students.toArray()) +// .forEach(student -> studyMap.put(student,student.getTotalStudyTime())); + Iterator iterator = students.iterator(); + while(iterator.hasNext()){ + Student student = (Student) iterator.next(); + studyMap.put(student,student.getTotalStudyTime()); + } + return studyMap; + } + + public static Instructors getInstructors() { + return instructors; + } + + public static Students getStudents() { + return students; + } +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/interfaces/EducatorTest.java b/src/test/java/io/zipcoder/interfaces/EducatorTest.java new file mode 100644 index 00000000..a867469c --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/EducatorTest.java @@ -0,0 +1,73 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Map; + +/** + * Create a testImplementation method that asserts that an Instructor is an instanceof a Teacher. + * Create a testInheritance method that asserts that a Instructor is an instanceof a Person. + * Create a testTeach method that ensures when an Instructor invokes the teach method, a respective + * student's totalStudyTime instance variable is incremented by the specified numberOfHours. + * Create a testLecture method that ensures when an Instructor invokes the lecture method, a respective + * array of students' totalStudyTime instance variables is incremented by numberOfHours/students.length. + */ +public class EducatorTest { + @Test + public void testTeacherImplementation(){ + Educator leon = Educator.LEON; + Assert.assertTrue(leon instanceof Teacher); + } + +// @Test +// public void testPersonInheritance(){ +// Educator dolio = Educator.DOLIO; +// Assert.assertTrue(dolio instanceof Person); +// } + + @Test + public void testTeach(){ + //given + Educator dolio = Educator.DOLIO; + Students students = Students.getInstance(); + Student nate = students.findById(0); + //when + dolio.teach(nate,5.0); + Double expected = 5.0; + Double actual = nate.getTotalStudyTime(); + //then + Assert.assertEquals(expected,actual); + } + + @Test + public void testLecture(){ + //given + Educator kris = Educator.KRIS; + Student[] ourClass = Students.getInstance().toArray(); + //when + kris.lecture(ourClass,20.0); + Double actual = Students.getInstance().findById(0).getTotalStudyTime(); + Double expected = 5.0; + //then + Assert.assertEquals(expected,actual); + } + + @Test + public void testLectureUsingEducator(){ + //given + Educator leon = Educator.LEON; + ZipCodeWilmington zcw = ZipCodeWilmington.getInstance(); + //when + zcw.hostLecture(leon,20.0); + Map studyMap = ZipCodeWilmington.getStudyMap(); + Double actual = studyMap.get(ZipCodeWilmington.getStudents().findById(0)); + Double expected = 5.0; + Double actualTeachTime = leon.getTimeWorked(); + Double expectedTeachTime = 20.0; + //then + Assert.assertEquals(expected, actual); + Assert.assertEquals(expectedTeachTime,actualTeachTime); + } + +} diff --git a/src/test/java/io/zipcoder/interfaces/InstructorSTest.java b/src/test/java/io/zipcoder/interfaces/InstructorSTest.java new file mode 100644 index 00000000..1d615c58 --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/InstructorSTest.java @@ -0,0 +1,18 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class InstructorSTest { + @Test + public void realTest(){ + Instructors instructors = Instructors.getInstance(); + Instructor retrievedLeon = instructors.findById(0); + + boolean instructorHasLeon = instructors.contains(retrievedLeon); + + Assert.assertTrue(instructorHasLeon); + } + + +} diff --git a/src/test/java/io/zipcoder/interfaces/InstructorTest.java b/src/test/java/io/zipcoder/interfaces/InstructorTest.java new file mode 100644 index 00000000..ecd89f79 --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/InstructorTest.java @@ -0,0 +1,63 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Create a TestInstructor class. + * Create a testImplementation method that asserts that an Instructor is an instanceof a Teacher. + * Create a testInheritance method that asserts that a Instructor is an instanceof a Person. + * Create a testTeach method that ensures when an Instructor invokes the teach method, a respective + * student's totalStudyTime instance variable is incremented by the specified numberOfHours. + * Create a testLecture method that ensures when an Instructor invokes the lecture method, a + * respective array of students' totalStudyTime instance variables is incremented by + * numberOfHours/students.length. + */ + +public class InstructorTest { + + @Test + public void implementationTest(){ + Instructor instructor = new Instructor(0, "Mr.Teach"); + Assert.assertTrue(instructor instanceof Teacher); + } + + @Test + public void inheritanceTest(){ + Instructor instructor = new Instructor(0, "Mr.Teach"); + Assert.assertTrue(instructor instanceof Person); + } + + @Test + public void teachTest(){ + Instructor instructor = new Instructor(0, "Mr.Teach"); + Student student = new Student(); + Double expected = 5.0; + instructor.teach(student,expected); + Double actual = student.getTotalStudyTime(); + Assert.assertEquals(expected, actual ); + } + + @Test + public void lectureTest(){ + Instructor instructor = new Instructor(0, "Mr.Teach"); + Student jake = new Student(0,"Jake"); + Student sue = new Student(1, "Sue"); + Student bob = new Student(2, "Bob"); + Student[] classroom = {jake, sue, bob}; + + instructor.lecture(classroom,15.0); + + Double exp = 5.0; + Double act1 = jake.getTotalStudyTime(); + Double act2 = sue.getTotalStudyTime(); + Double act3 = bob.getTotalStudyTime(); + + Assert.assertEquals(exp,act1); + Assert.assertEquals(exp,act2); + Assert.assertEquals(exp,act3); + } + + + +} diff --git a/src/test/java/io/zipcoder/interfaces/PeopleTest.java b/src/test/java/io/zipcoder/interfaces/PeopleTest.java new file mode 100644 index 00000000..5593a069 --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/PeopleTest.java @@ -0,0 +1,57 @@ +package io.zipcoder.interfaces; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Test; + +/** + * Create a TestPeople class. + * Create a testAdd method which ensures that our personList in our People class + * populated with respective Person objects following invocation of the add method. + * Create a testRemove method which ensures that the personList in a People object is + * depopulated with a respective Person object following the invokation of the remove method. + * Create a testFindById method which ensures that a respective Person object with + * a respective id field is returned upon invokation of the findById method on a respective People object. + */ + +public class PeopleTest { + @Test + public void addTest(){ + //given + People peeps = Students.getInstance(); + Person nick = new Person(10,"nick"); + //when + peeps.add(nick); + //then + boolean peepsHasNick= peeps.contains(nick); + Assert.assertTrue(peepsHasNick); + peeps.removeById(10); + + } + + @Test + public void removeTest(){ + //given + People peeps = Students.getInstance(); + Person jason = new Person(12,"Jason"); + peeps.add(jason); + //when + peeps.removePerson(jason); + boolean peepsHasJason = peeps.contains(jason); + //then + Assert.assertFalse(peepsHasJason); + } + + @Test + public void findByIdTest(){ + //given + People peeps = Students.getInstance(); + Person laura = new Person(16, "Laura"); + peeps.add(laura); + //when + Person retrieved = peeps.findById(16); + //then + Assert.assertEquals(laura,retrieved); + peeps.removePerson(laura); + } +} diff --git a/src/test/java/io/zipcoder/interfaces/StudentSTest.java b/src/test/java/io/zipcoder/interfaces/StudentSTest.java new file mode 100644 index 00000000..8d41756b --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/StudentSTest.java @@ -0,0 +1,32 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +public class StudentSTest { + @Test + public void test(){ + Students students = Students.getInstance(); + Student john = new Student(5,"John"); + students.add(john); + //when + Person retrieved1 = students.findById(5); + //then + Assert.assertEquals(john,retrieved1); + students.removePerson(john); + } + + @Test + public void realTest(){ + //given + Students students = Students.getInstance(); + //when + Student nateCopy = students.findById(0); + boolean hasNate = students.contains(nateCopy); + //then + Assert.assertTrue(hasNate); + + } + + +} diff --git a/src/test/java/io/zipcoder/interfaces/StudentTest.java b/src/test/java/io/zipcoder/interfaces/StudentTest.java new file mode 100644 index 00000000..ccc80f02 --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/StudentTest.java @@ -0,0 +1,37 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Create a TestStudent class. + * Create a testImplementation method that asserts that a Student is an instanceof a Learner. + * Create a testInheritance method that asserts that a Student is an instanceof a Person. + * Create a testLearn method that ensures a Student's totalStudyTime instance variable is + * incremented by the specified numberOfHours by invoking the .learn method. + * + */ + +public class StudentTest { + @Test + public void studentImplementationTest(){ + Student student1 = new Student(); + Assert.assertTrue(student1 instanceof Learner); + } + + @Test + public void studentInheritanceTest(){ + Student student1 = new Student(); + Assert.assertTrue(student1 instanceof Person); + } + + @Test + public void studentLearnTest(){ + Student student1 = new Student(); + Double exp = 5.0; + student1.learn(exp); + Double act = student1.getTotalStudyTime(); + Assert.assertEquals(exp,act); + + } +} diff --git a/src/test/java/io/zipcoder/interfaces/TestPerson.java b/src/test/java/io/zipcoder/interfaces/TestPerson.java index d64cd2f0..c1f5efc1 100644 --- a/src/test/java/io/zipcoder/interfaces/TestPerson.java +++ b/src/test/java/io/zipcoder/interfaces/TestPerson.java @@ -1,5 +1,30 @@ package io.zipcoder.interfaces; +import org.junit.Assert; +import org.junit.Test; + public class TestPerson { + @Test + public void constructorTest(){ + //given + String name = "John"; + long id = 12; + //when + Person person = new Person(id,name); + //then + Assert.assertEquals(id,person.getId()); + Assert.assertEquals(name,person.getName()); + } + @Test + public void setNameTest(){ + //given + String name = "John"; + long id = 12; + Person person = new Person(id,name); + //when + person.setName("Jason"); + //then + Assert.assertEquals("Jason", person.getName()); + } } diff --git a/src/test/java/io/zipcoder/interfaces/ZipCodeWilmingtonTest.java b/src/test/java/io/zipcoder/interfaces/ZipCodeWilmingtonTest.java new file mode 100644 index 00000000..0b821170 --- /dev/null +++ b/src/test/java/io/zipcoder/interfaces/ZipCodeWilmingtonTest.java @@ -0,0 +1,39 @@ +package io.zipcoder.interfaces; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class ZipCodeWilmingtonTest { + + @Test + public void testHostLecture_byTeacher(){ + ZipCodeWilmington zcw = ZipCodeWilmington.getInstance(); + Teacher leon = ZipCodeWilmington.getInstructors().findById(0); + + zcw.hostLecture(leon, 20.0); + Map studyMap = ZipCodeWilmington.getStudyMap(); + + Double actual = studyMap.get(ZipCodeWilmington.getStudents().findById(0)); + Double expected = 5.0; + + Assert.assertEquals(expected, actual); + } + + @Test + public void testHostLecture_byId(){ + //given + ZipCodeWilmington zcw = ZipCodeWilmington.getInstance(); + //when + zcw.hostLecture(1,40.0); + Map studyMap = ZipCodeWilmington.getStudyMap(); + Double actual = studyMap.get(ZipCodeWilmington.getStudents().findById(1)); + Double expected = 10.0; + + //then + Assert.assertEquals(expected,actual); + } + +}