Skip to content

Commit

Permalink
🌿
Browse files Browse the repository at this point in the history
  • Loading branch information
GuusDb committed Mar 25, 2022
1 parent 002b795 commit 1c627aa
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domein;

import java.util.Date;

public class Channel {

private final int numberChannel;

public Channel(int number) {
this.numberChannel = number;
}

public int getNumberChannel() {
return numberChannel;
}

public Program getCurrentProgram()
{
return new Program(new Date(), this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package domein;

import java.util.Date;

public class Program {

private final Channel channel;
private final Date date;

public Program(Date date, Channel channel) {
this.date= date;
this.channel = channel;
}

public int getNrChannel() {
return channel.getNumberChannel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package domein;

public class Television {

//TODO attributes


public Television(int maxChannel) {
//TODO
}

public Program getNextProgram() {
//TODO
return null;
}

public Program getPrevProgram() {
//TODO
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package oefeningiteratorstarter;

import domein.Program;
import domein.Television;

public class OefeningIteratorStarter {

private static final int MAX = 5;

public static void main(String[] args) {
Television television = new Television(MAX);
System.out.printf("MAX channels %d%n", MAX);

Program program = television.getNextProgram();
System.out.printf("next %d%n", program.getNrChannel());
program = television.getNextProgram();
System.out.printf("next %d%n", program.getNrChannel());
program = television.getPrevProgram();
System.out.printf("prev %d%n", program.getNrChannel());
program = television.getPrevProgram();
System.out.printf("prev %d%n", program.getNrChannel());
program = television.getPrevProgram();
System.out.printf("prev %d%n", program.getNrChannel());
program = television.getNextProgram();
System.out.printf("next %d%n", program.getNrChannel());

for (int i = 1; i < MAX; i++) {
program = television.getNextProgram();
System.out.printf("next %d%n", program.getNrChannel());
}

program = television.getPrevProgram();
System.out.printf("prev %d%n", program.getNrChannel());
program = television.getNextProgram();
System.out.printf("next %d%n", program.getNrChannel());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package testen;

import domein.Program;
import domein.Television;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TelevisionTest {

private Television television;
private final int MAX = 5;

@BeforeEach
public void before() {
television = new Television(MAX);
}

@Test
public void testChannels() {
Program program = television.getNextProgram();
Assertions.assertEquals(1, program.getNrChannel());
program = television.getNextProgram();
Assertions.assertEquals(2, program.getNrChannel());
program = television.getPrevProgram();
Assertions.assertEquals(1, program.getNrChannel());
program = television.getPrevProgram();
Assertions.assertEquals(0, program.getNrChannel());
program = television.getPrevProgram();
Assertions.assertEquals(4, program.getNrChannel());
program = television.getNextProgram();
Assertions.assertEquals(0, program.getNrChannel());
for (int i = 1; i < MAX; i++) {
program = television.getNextProgram();
Assertions.assertEquals(i, program.getNrChannel());
}
program = television.getPrevProgram();
Assertions.assertEquals(3, program.getNrChannel());
program = television.getNextProgram();
Assertions.assertEquals(4, program.getNrChannel());
}
@Test
public void testVolgendeChannels() {
int verwachteNrChannel = 1;
for (int i = 0; i < 20; i++) {
Program program = television.getNextProgram();
Assertions.assertEquals(verwachteNrChannel++, program.getNrChannel());
if (verwachteNrChannel == MAX) {
verwachteNrChannel = 0;
}
}
}
@Test
public void testPrevChannels() {
int verwachteNrChannel = MAX - 1;
for (int i = 0; i < 20; i++) {
Program program = television.getPrevProgram();
Assertions.assertEquals(verwachteNrChannel--, program.getNrChannel());
if (verwachteNrChannel < 0) {
verwachteNrChannel = MAX - 1;
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Visual Paradigm: DO NOT MODIFY THIS FILE!
#Thu Jan 13 21:49:09 CET 2022
DiagramId=NBSfGlqGAqACAhKl
Create=false
ProjectId=OBcfGlqGAqACAgwO

0 comments on commit 1c627aa

Please sign in to comment.