Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // lab 4 task
- import java.util.ArrayList;
- import java.util.List;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.Test;
- import java.util.ArrayList;
- import java.util.List;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertSame;
- public class Conference {
- public static double TICKET_PRICE = 10.90;
- public static double EMT_DISCOUNT = 0.5;
- public static double WEB_DISCOUNT = 0.3;
- private List<Student> attendees;
- private int capacity;
- public Conference(int capacity) {
- this.attendees = new ArrayList<>(capacity);
- this.capacity = capacity;
- }
- public double calculateTotalPricePaid() {
- double price = 0;
- for (Student p : attendees) {
- if (p.getCourse().name().equals("EMT"))
- price += (1 - EMT_DISCOUNT) * TICKET_PRICE;
- else if (p.getCourse().name().equals("WEB"))
- price += (1 - WEB_DISCOUNT) * TICKET_PRICE;
- else
- price += TICKET_PRICE;
- }
- return price;
- }
- public boolean addAttendeeToConference(Student student) {
- if ((this.attendees.size() < capacity) || tripleCapacity()) {
- this.attendees.add(student);
- return true;
- } else return false;
- }
- public boolean tripleCapacity() {
- if (this.capacity * 3 > 10000)
- return false;
- this.capacity *= 3;
- return true;
- }
- public List<Student> getAttendees() {
- return attendees;
- }
- public int getCapacity() {
- return capacity;
- }
- }
- class Student {
- private String name;
- private String surname;
- private Course course;
- private int age;
- public Student(String name, String surname, Course course, int age) {
- this.name = name;
- this.surname = surname;
- this.course = course;
- this.age = age;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSurname() {
- return surname;
- }
- public void setSurname(String surname) {
- this.surname = surname;
- }
- public Course getCourse() {
- return course;
- }
- public void setCourse(Course course) {
- this.course = course;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- @Override
- public String toString() {
- return "Student{" +
- "name='" + name + '\'' +
- ", surname='" + surname + '\'' +
- ", course=" + course +
- ", age=" + age +
- '}';
- }
- }
- enum Course {
- OS,
- EMT,
- SKIT,
- WEB,
- OTHER
- }
- class ConferenceTest {
- public int CAPACITY = 3333;
- Conference conference = new Conference(CAPACITY);
- // TODO: Add tests here!
- // Create a new Conference for every new test
- @BeforeEach
- void setUp() {
- conference = new Conference(CAPACITY);
- }
- // TEST 1: Calculate Total price with no EMT or Web students attending
- @Test
- public void CalculatePriceWithEMTandWebStudentsExcluded(){
- List<Student> attendees = new ArrayList<>();
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- conference.addAttendeeToConference(student);
- double price = conference.calculateTotalPricePaid();
- assertEquals(10.90,price,0);
- }
- // TEST 2: Calculate Total price with EMT and Web as well as 'normal' students attending
- // Also Test set methods for Student Class
- @Test
- public void CalculatePriceWithEMTandWebStudentsIncluded(){
- List<Student> attendees = new ArrayList<>();
- Student student1 = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- Student student2 = new Student("Ev","Genija",Course.valueOf("WEB"),21);
- Student student3 = new Student("Angela","Angeleska",Course.valueOf("OTHER"),20);
- student3.setAge(20);
- student3.setName("Angela");
- student3.setCourse(Course.valueOf("EMT"));
- student3.setSurname("Angeleska");
- conference.addAttendeeToConference(student1);
- conference.addAttendeeToConference(student2);
- conference.addAttendeeToConference(student3);
- double price = conference.calculateTotalPricePaid();
- assertEquals(23.98,price,0);
- }
- // TEST 3: Test getCapacity() function after creating a Conference object
- @Test
- public void ConferenceCapacity(){
- assertEquals(CAPACITY,conference.getCapacity());
- }
- // TEST 4: Test TripleCapacity() function
- @Test
- public void ConferenceTripleCapacity(){
- int initial_capacity = conference.getCapacity();
- conference.tripleCapacity();
- assertEquals(initial_capacity*3,conference.getCapacity());
- }
- // TEST 5: Test Attendess List, or in other words the getAttendees() method
- @Test
- public void ConferenceAttendeesList(){
- List<Student> attendees = new ArrayList<>();
- Student student1 = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- Student student2 = new Student("Ev","Genija",Course.valueOf("WEB"),21);
- Student student3 = new Student("Angela","Angeleska",Course.valueOf("OTHER"),20);
- attendees.add(student1);
- attendees.add(student2);
- attendees.add(student3);
- conference.addAttendeeToConference(student1);
- conference.addAttendeeToConference(student2);
- conference.addAttendeeToConference(student3);
- assertEquals(attendees,conference.getAttendees());
- }
- // TEST 6: Test Adding Attendees over the limit, but this time the capacity is more than 3333 students (3334 exactly)
- @Test
- public void AddingAttendeeToConferenceOverTheLimit(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- Conference conference2 = new Conference(3334);
- for(int i=0;i<3334;i++){
- conference2.addAttendeeToConference(student);
- }
- assertEquals(false,conference2.addAttendeeToConference(student));
- }
- // TEST 7: Simular situation as the previous test, but now we are trying to kill the mutant in line 35 of the Conference class,
- // , that is this.attendees.size() >= capacity || tripleCapacity()
- @Test
- public void AddingFirstAttendeeToConference(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- Conference conference2 = new Conference(3334);
- assertEquals(true,conference2.addAttendeeToConference(student));
- }
- // TEST 8: Testing the tripleCapacity() method with less than 3334 capacity.
- @Test
- public void TripleCapacityLessThan3334(){
- assertEquals(true, conference.tripleCapacity());
- }
- // TEST 9: Testing the tripleCapacity() method with more than 3333 capacity.
- @Test
- public void TripleCapacityNotLessThan3334(){
- Conference conference2 = new Conference(3334);
- assertEquals(false, conference2.tripleCapacity());
- }
- // TEST 10: Testing getter in Student Class
- @Test
- public void StudentName(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- String name = student.getName();
- assertEquals("Dzoce",name);
- }
- // TEST 11: Testing getter in Student Class
- @Test
- public void StudentSurname(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- String surname = student.getSurname();
- assertEquals("Srce",surname);
- }
- // TEST 12: Testing getter in Student Class
- @Test
- public void StudentCourse(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- Course course = student.getCourse();
- assertEquals("OS",course.name());
- }
- // TEST 13: Testing getter in Student Class
- @Test
- public void StudentAge(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- int age = student.getAge();
- assertEquals(22,age);
- }
- // TEST 14: Testing getter in Student Class
- @Test
- public void StudentInfo(){
- Student student = new Student("Dzoce","Srce",Course.valueOf("OS"),22);
- String info = student.toString();
- assertEquals("Student{name='Dzoce', surname='Srce', course=OS, age=22}",info);
- }
- //We are unable to strongly kill the mutant in line 42 because the mutanted version is of the if statement ' this.capacity*3 >= 10000 '
- //however there is no int for which this.capacity*3 > 10000 and this.capacity*3 >= 10000 return either the pair T-F or the pair F-T.
- //thus by definition we are unable to kill the mutant.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement