ibrahimemin11

InheritanceLabPractice

Aug 1st, 2025
119
0
10 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.52 KB | None | 0 0
  1. package junit_tests;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import org.junit.Test;
  6.  
  7. import model.*;
  8.  
  9. /*
  10.  * Requirement: Any classes you create must reside in the `model` package and be imported properly.
  11.  * For example, creating a new class `Foo` in the `model` package should result in:
  12.  *  import model.Foo;
  13.  *
  14.  * All attributes you declare in the model classes must be private.
  15.  *  If necessary, define public accessors/getters and/or mutators/setters for these private attributes.
  16.  */
  17.  
  18. public class StarterTests {
  19.     /*
  20.      * Programming Requirements:
  21.      *
  22.      *  - You are only allowed to use primitive arrays (e.g., int[], String[], Product[])
  23.      *      for declaring attributes and implementing the idea of collections.
  24.      *  - Any use of a Java library class or method is forbidden
  25.      *      (that is, use selections and loops to build your solution from scratch instead):
  26.      *  - Here are some examples of forbidden classes/methods:
  27.      *      - Arrays class (e.g., Arrays.copyOf)
  28.      *      - System class (e.g., System.arrayCopy)
  29.      *      - ArrayList class
  30.      *      - String class (e.g., substring).
  31.      *  - The use of some library classes does not require an import statement,
  32.      *      but these classes are also forbidden to be used.
  33.      *  - Here are the exceptions (library methods which you are allowed to use if needed):
  34.      *      - String class (equals, format)
  35.      *
  36.      * Violating the above programming requirements will result in a penalty (see lab instructions for details).
  37.      *
  38.      * Tests included in this class serve as documentation on how instances of an Apple AppStore operates.
  39.      *
  40.      * Before attempting this lab, it is expected that you already completed background study materials:
  41.      *  1. Review Tutorial Series on OOP in Java (Part 1 and Part 2):
  42.      *      https://www.eecs.yorku.ca/~jackie/teaching/tutorials/index.html#refurbished_store
  43.      *  2. Written Notes on Reference-Typed, Multi-Valued Attributes:
  44.      *      https://www.eecs.yorku.ca/~jackie/teaching/lectures/2025/S/EECS2030/notes/EECS2030_S25_Tracing_PointCollectorTester.pdf
  45.      *  3. Written Notes on Inferring Classes from JUnit Tests:
  46.      *      https://www.eecs.yorku.ca/~jackie/teaching/lectures/2025/S/EECS2030/notes/EECS2030_S25_Inferring_Classes_from_JUnit.pdf
  47.      *
  48.      * Be sure to also read the following sections from your Lab1 instructions PDF:
  49.      *  - The `Requirements of this Lab` section (page 3)
  50.      *  - Section 2.3 The Building Design Problem
  51.      *  - Section 2.4 Hints and Requirements
  52.      *
  53.      * Programming IDEs such as Eclipse are able to fix some compilation errors for you.
  54.      * However, you are advised to follow the guidance as specified in the written notes above
  55.      * to fix these compilation errors manually, because:
  56.      *  1) it helps you better understand how the intended classes and methods work together; and
  57.      *  2) you may be tested in a written test or exam without the assistance of IDEs.
  58.      */
  59.  
  60.     /*
  61.      * Tests related to the Channel class.
  62.      */
  63.    
  64.     @Test
  65.     public void test_channel_01a() {
  66.         /*
  67.          * Create a channel with the specified name and
  68.          *  maximum 50 followers and maximum 100 videos to release.
  69.          * See the lab manual to see what to expect when a preset maximum is exceeded.
  70.          */
  71.         Channel ch = new Channel("Cafe Music BGM", 50, 100);
  72.         assertEquals("Cafe Music BGM released no videos and has no followers.", ch.toString());
  73.     }
  74.    
  75.     @Test
  76.     public void test_channel_01b() {
  77.         Channel ch = new Channel("Cafe Music BGM", 50, 100);
  78.        
  79.         /*
  80.          * `ch` releases two new videos.
  81.          */
  82.         ch.releaseANewVideo("Monday Jazz");
  83.         assertEquals("Cafe Music BGM released <Monday Jazz> and has no followers.", ch.toString());
  84.        
  85.         ch.releaseANewVideo("Tuesday Jazz");
  86.         assertEquals("Cafe Music BGM released <Monday Jazz, Tuesday Jazz> and has no followers.", ch.toString());
  87.     }
  88.    
  89.     /*
  90.      * Tests related to the Follower classes.
  91.      */
  92.    
  93.     @Test
  94.     public void test_follower_01a() {
  95.         /*
  96.          * Create a subscriber with the specified name and
  97.          *  maximum 20 channels to follow and maximum 40 videos to be recommended by the channels.
  98.          * See the lab manual to see what to expect when a preset maximum is exceeded.
  99.          */
  100.         Follower f = new Subscriber("Alan", 20, 40);
  101.         assertEquals("Subscriber Alan follows no channels and has no recommended videos.", f.toString());
  102.     }
  103.    
  104.     @Test
  105.     public void test_follower_01b() {
  106.         /*
  107.          * Create a monitor with the specified name and maximum 20 channels to follow.
  108.          * See the lab manual to see what to expect when a preset maximum is exceeded.
  109.          */
  110.         Follower f = new Monitor("Stat Sensor A", 20);
  111.         assertEquals("Monitor Stat Sensor A follows no channels.", f.toString());
  112.     }
  113.    
  114.     /*
  115.      * More tests related to the Channel class.
  116.      */
  117.    
  118.     @Test
  119.     public void test_channel_01c() {
  120.         /*
  121.          * Note that the two channels are set with different maximums for
  122.          *  the allowed numbers of followers and videos to release.
  123.          */
  124.         Channel ch1 = new Channel("Cafe Music BGM", 50, 100);
  125.         Channel ch2 = new Channel("I Love You Venice", 60, 135);
  126.        
  127.         /*
  128.          * Note that the followers are set with different maximums for the allowed numbers of channels.
  129.          */
  130.         Follower f1 = new Subscriber("Alan", 20, 40);
  131.         Follower f2 = new Monitor("Stat Sensor A", 60);
  132.        
  133.         /*
  134.          * Let `f1` follow `ch1` (which updates both the context object `ch1` and argument object `f1`).
  135.          *
  136.          * You can assume that a follower, once added to a channel, will not be added to that channel again.
  137.          */
  138.         ch1.follow(f1);
  139.         assertEquals("Cafe Music BGM released no videos and is followed by [Subscriber Alan].", ch1.toString());
  140.         assertEquals("Subscriber Alan follows [Cafe Music BGM] and has no recommended videos.", f1.toString());
  141.        
  142.         /*
  143.          * Let `f2` follow `ch1` (which updates both the context object `ch1` and argument object `f2`).
  144.          */
  145.         ch1.follow(f2);
  146.         assertEquals("Cafe Music BGM released no videos and is followed by [Subscriber Alan, Monitor Stat Sensor A].", ch1.toString());
  147.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM].", f2.toString());
  148.        
  149.         /*
  150.          * Let `f2` follow `ch2` (which updates both the context object `ch2` and argument object `f2`).
  151.          */
  152.         ch2.follow(f2);
  153.         assertEquals("I Love You Venice released no videos and is followed by [Monitor Stat Sensor A].", ch2.toString());
  154.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM, I Love You Venice].", f2.toString());
  155.        
  156.         /*
  157.          * Let `f1` follow `ch2` (which updates both the context object `ch2` and argument object `f1`).
  158.          */
  159.         ch2.follow(f1);
  160.         assertEquals("I Love You Venice released no videos and is followed by [Monitor Stat Sensor A, Subscriber Alan].", ch2.toString());
  161.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and has no recommended videos.", f1.toString());
  162.        
  163.         /*
  164.          * Jackie's suggestion: You may test more cases of letting multiple subscribers and/or monitors follow multiple channels.
  165.          */
  166.     }
  167.    
  168.     @Test
  169.     public void test_channel_01d() {
  170.         Channel ch1 = new Channel("Cafe Music BGM", 50, 100);
  171.         Channel ch2 = new Channel("I Love You Venice", 60, 135);
  172.        
  173.         Follower f1 = new Subscriber("Alan", 20, 40);
  174.         Follower f2 = new Monitor("Stat Sensor A", 60);
  175.        
  176.         ch1.follow(f1);
  177.         ch1.follow(f2);
  178.         ch2.follow(f2);
  179.         ch2.follow(f1);
  180.        
  181.         assertEquals("Cafe Music BGM released no videos and is followed by [Subscriber Alan, Monitor Stat Sensor A].", ch1.toString());
  182.         assertEquals("I Love You Venice released no videos and is followed by [Monitor Stat Sensor A, Subscriber Alan].", ch2.toString());
  183.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and has no recommended videos.", f1.toString());
  184.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM, I Love You Venice].", f2.toString());
  185.        
  186.         /*
  187.          * Let `f1` stop following `ch1` (which updates both the context object `ch1` and argument object `f1`).
  188.          */
  189.         ch1.unfollow(f1);
  190.        
  191.         assertEquals("Cafe Music BGM released no videos and is followed by [Monitor Stat Sensor A].", ch1.toString());
  192.         assertEquals("I Love You Venice released no videos and is followed by [Monitor Stat Sensor A, Subscriber Alan].", ch2.toString());
  193.         assertEquals("Subscriber Alan follows [I Love You Venice] and has no recommended videos.", f1.toString());
  194.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM, I Love You Venice].", f2.toString());
  195.        
  196.         /*
  197.          * Let `f1` stop following `ch2` (which updates both the context object `ch2` and argument object `f1`).
  198.          */
  199.         ch2.unfollow(f1);
  200.         assertEquals("Cafe Music BGM released no videos and is followed by [Monitor Stat Sensor A].", ch1.toString());
  201.         assertEquals("I Love You Venice released no videos and is followed by [Monitor Stat Sensor A].", ch2.toString());
  202.         assertEquals("Subscriber Alan follows no channels and has no recommended videos.", f1.toString());
  203.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM, I Love You Venice].", f2.toString());
  204.        
  205.         /*
  206.          * Let `f2` stop following `ch2` (which updates both the context object `ch2` and argument object `f2`).
  207.          */
  208.         ch2.unfollow(f2);
  209.         assertEquals("Cafe Music BGM released no videos and is followed by [Monitor Stat Sensor A].", ch1.toString());
  210.         assertEquals("I Love You Venice released no videos and has no followers.", ch2.toString());
  211.         assertEquals("Subscriber Alan follows no channels and has no recommended videos.", f1.toString());
  212.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM].", f2.toString());
  213.        
  214.        
  215.         Follower f3 = new Subscriber("Mark", 20, 45);
  216.         ch2.follow(f3);
  217.         assertEquals("Subscriber Mark follows [I Love You Venice] and has no recommended videos.", f3.toString());
  218.         assertEquals("I Love You Venice released no videos and is followed by [Subscriber Mark].", ch2.toString());
  219.         assertEquals("Cafe Music BGM released no videos and is followed by [Monitor Stat Sensor A].", ch1.toString());
  220.        
  221.  
  222.         ch1.unfollow(f3);
  223.         /*
  224.          * Since `f3` is not following `ch1`, unfollowing it should have no effect.
  225.          */
  226.         assertEquals("Subscriber Mark follows [I Love You Venice] and has no recommended videos.", f3.toString());
  227.         assertEquals("I Love You Venice released no videos and is followed by [Subscriber Mark].", ch2.toString());
  228.         assertEquals("Cafe Music BGM released no videos and is followed by [Monitor Stat Sensor A].", ch1.toString());
  229.        
  230.         /*
  231.          * Jackie's suggestions:
  232.          *  1. You may test more cases of letting a follower stop following a channel
  233.          *      (in cases where the follower is in the beginning, middle, or end of the channel's follower list, and
  234.          *       in cases where the channel is in the beginning, middle, or end of the follower's channel list).
  235.          *  2. You may test more cases of unfollowing a subscriber or monitor from a channel which it does not follow.
  236.          */
  237.     }
  238.    
  239.     @Test
  240.     public void test_channel_02a() {
  241.         Channel ch = new Channel("Cafe Music BGM", 50, 100);
  242.         assertEquals("Cafe Music BGM released no videos and has no followers.", ch.toString());
  243.        
  244.         /*
  245.          * You can assume that no duplicated video names will be released across all channels.
  246.          * That is, names of videos released by all channels are unique.
  247.          *
  248.          * Assume that channel videos, once released, will not be removed.
  249.          */
  250.         ch.releaseANewVideo("Jazz Piano Radio");
  251.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and has no followers.", ch.toString());
  252.        
  253.         ch.releaseANewVideo("Starbucks Music Playlist 2021");
  254.         assertEquals("Cafe Music BGM released <Jazz Piano Radio, Starbucks Music Playlist 2021> and has no followers.", ch.toString());
  255.        
  256.         Follower f1 = new Subscriber("Alan", 20, 40);
  257.         Follower f2 = new Monitor("Stat Sensor A", 60);
  258.        
  259.         /*
  260.          * Given that `f1` and `f2` only start following `ch` after it released the two videos,
  261.          *  those two videos will not be recommended to `f1` and `f2`.
  262.          *
  263.          * That is, a follower is only recommended videos that are released after they start following a channel.
  264.          */
  265.        
  266.         ch.follow(f1);
  267.         assertEquals("Cafe Music BGM released <Jazz Piano Radio, Starbucks Music Playlist 2021> and is followed by [Subscriber Alan].", ch.toString());
  268.         assertEquals("Subscriber Alan follows [Cafe Music BGM] and has no recommended videos.", f1.toString());
  269.         assertEquals("Monitor Stat Sensor A follows no channels.", f2.toString());
  270.        
  271.         ch.follow(f2);
  272.         assertEquals("Cafe Music BGM released <Jazz Piano Radio, Starbucks Music Playlist 2021> and is followed by [Subscriber Alan, Monitor Stat Sensor A].", ch.toString());
  273.         assertEquals("Subscriber Alan follows [Cafe Music BGM] and has no recommended videos.", f1.toString());
  274.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM].", f2.toString());
  275.     }
  276.    
  277.     @Test
  278.     public void test_channel_02b() {
  279.         Channel ch1 = new Channel("Cafe Music BGM", 50, 100);
  280.         Channel ch2 = new Channel("I Love You Venice", 60, 135);
  281.        
  282.         Follower f1 = new Subscriber("Alan", 20, 40);
  283.         Follower f2 = new Monitor("Stat Sensor A", 30);
  284.         Follower f3 = new Subscriber("Mark", 20, 40);
  285.        
  286.         ch1.follow(f1);
  287.         ch2.follow(f1);
  288.         ch2.follow(f2);
  289.         ch1.follow(f2);
  290.         ch2.follow(f3);
  291.         ch1.follow(f3);
  292.        
  293.         assertEquals("Cafe Music BGM released no videos and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  294.         assertEquals("I Love You Venice released no videos and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch2.toString());
  295.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and has no recommended videos.", f1.toString());
  296.         assertEquals("Monitor Stat Sensor A follows [I Love You Venice, Cafe Music BGM].", f2.toString());
  297.         assertEquals("Subscriber Mark follows [I Love You Venice, Cafe Music BGM] and has no recommended videos.", f3.toString());
  298.        
  299.         /*
  300.          * When a video is released by the channel, it is immediately recommended to all its subscribers (not monitors).
  301.          *
  302.          * Hints on implementing `releaseANewVideo`:
  303.          *  See the two updates expressed in the following two assertions.
  304.          */
  305.         ch1.releaseANewVideo("Jazz Piano Radio");
  306.         /* Update 1: video release updated on `ch1` */
  307.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  308.         /* Update 2: video recommendation updated on all subscribers: `f1` and `f3` */
  309.         assertEquals("Subscriber Mark follows [I Love You Venice, Cafe Music BGM] and is recommended <Jazz Piano Radio>.", f3.toString());
  310.        
  311.         /* no changes on the other channel and the monitor */
  312.         assertEquals("I Love You Venice released no videos and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch2.toString());
  313.         assertEquals("Monitor Stat Sensor A follows [I Love You Venice, Cafe Music BGM].", f2.toString());
  314.        
  315.         ch2.releaseANewVideo("Baroque Live Music 24/7");
  316.         /* Update 1: video release updated on `ch2` */
  317.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch2.toString());
  318.         /* Update 2: video recommendation updated on all subscribers: `f1` and `f3` */
  319.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", f1.toString());
  320.         assertEquals("Subscriber Mark follows [I Love You Venice, Cafe Music BGM] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", f3.toString());
  321.        
  322.         /* no changes on the other channel and the monitor */
  323.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  324.         assertEquals("Monitor Stat Sensor A follows [I Love You Venice, Cafe Music BGM].", f2.toString());
  325.        
  326.         /*
  327.          * Jackie's suggestion: You may test more cases of a channel's new video release causing
  328.          *                          more than one subscribers to be updated on their lists of recommended videos.
  329.          */
  330.     }
  331.    
  332.     @Test
  333.     public void test_channel_03a() {
  334.         Channel ch1 = new Channel("Cafe Music BGM", 50, 100);
  335.         Channel ch2 = new Channel("I Love You Venice", 60, 135);
  336.        
  337.         Subscriber sub1 = new Subscriber("Alan", 20, 40);
  338.         Subscriber sub2 = new Subscriber("Mark", 20, 40);
  339.         Monitor mon1 = new Monitor("Stat Sensor A", 30);
  340.        
  341.         ch1.follow(sub1);
  342.         ch1.follow(mon1);
  343.         ch1.follow(sub2);
  344.        
  345.         ch2.follow(mon1);
  346.         ch2.follow(sub2);
  347.         ch2.follow(sub1);
  348.        
  349.        
  350.         ch1.releaseANewVideo("Jazz Piano Radio");
  351.         ch2.releaseANewVideo("Baroque Live Music 24/7");
  352.        
  353.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  354.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  355.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  356.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  357.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM, I Love You Venice].", mon1.toString());
  358.        
  359.         /*
  360.          * Subscriber `sub1` watched Jazz Piano Radio for 20 minutes.
  361.          *
  362.          * After a subscriber watched a recommended video of a channel,
  363.          *  the watch time is immediately used to update the statistics of all that channel's monitors (not subscribers).
  364.          *
  365.          * Assume that the second argument of method `watch` is always an integer specifying the watch time in terms of minutes.
  366.          *
  367.          * Since video names across all channels are assumed to be unique,
  368.          *  the `watch` method should be able to figure out to which channel the specified video name belongs.
  369.          */
  370.         sub1.watch("Jazz Piano Radio", 20);
  371.         /*
  372.          * Statistics for the watched video is updated for `mon1`.
  373.          * For the average watch time, display the value with two digits after the decimal point.
  374.          */
  375.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 1, max watch time: 20, avg watch time: 20.00}, I Love You Venice].", mon1.toString());
  376.         /* All other channels and subscribers remain unchanged. */
  377.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  378.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  379.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  380.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  381.        
  382.         /*
  383.          * Subscriber `sub2` watched Jazz Piano Radio for 30 minutes.
  384.          */
  385.         sub2.watch("Jazz Piano Radio", 30);
  386.         /*
  387.          * Statistics for the watched video is updated for `mon1`.
  388.          */
  389.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 2, max watch time: 30, avg watch time: 25.00}, I Love You Venice].", mon1.toString());
  390.         /* All other channels and subscribers remain unchanged. */
  391.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  392.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  393.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  394.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  395.        
  396.         /*
  397.          * Subscriber `sub1` watched Jazz Piano Radio again for 15 minutes.
  398.          */
  399.         sub1.watch("Jazz Piano Radio", 15);
  400.         /*
  401.          * Statistics for the watched video is updated for `mon1`.
  402.          */
  403.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 3, max watch time: 30, avg watch time: 21.67}, I Love You Venice].", mon1.toString());
  404.         /* All other channels and subscribers remain unchanged. */
  405.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  406.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  407.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  408.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  409.        
  410.         /*
  411.          * Subscriber `sub2` watched Baroque Live Music 24/7 for 11 minutes.
  412.          */
  413.         sub2.watch("Baroque Live Music 24/7", 11);
  414.         /*
  415.          * Statistics for the watched video is updated for `mon1`.
  416.          */
  417.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 3, max watch time: 30, avg watch time: 21.67}, I Love You Venice {#views: 1, max watch time: 11, avg watch time: 11.00}].", mon1.toString());
  418.         /* All other channels and subscribers remain unchanged. */
  419.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  420.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  421.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  422.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  423.         /*
  424.          * Subscriber `sub1` watched Baroque Live Music 24/7 for 8 minutes.
  425.          */
  426.         sub1.watch("Baroque Live Music 24/7", 8);
  427.         /*
  428.          * Statistics for the watched video is updated for `mon1`.
  429.          */
  430.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 3, max watch time: 30, avg watch time: 21.67}, I Love You Venice {#views: 2, max watch time: 11, avg watch time: 9.50}].", mon1.toString());
  431.         /* All other channels and subscribers remain unchanged. */
  432.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  433.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  434.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  435.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  436.        
  437.         /*
  438.          * Subscriber `sub2` watched Baroque Live Music 24/7 again for 18 minutes.
  439.          */
  440.         sub2.watch("Baroque Live Music 24/7", 18);
  441.         /*
  442.          * Statistics for the watched video is updated for `mon1`.
  443.          */
  444.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 3, max watch time: 30, avg watch time: 21.67}, I Love You Venice {#views: 3, max watch time: 18, avg watch time: 12.33}].", mon1.toString());
  445.         /* All other channels and subscribers remain unchanged. */
  446.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  447.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  448.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  449.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  450.     }
  451.    
  452.     @Test
  453.     public void test_channel_03b() {
  454.         Channel ch1 = new Channel("Cafe Music BGM", 50, 100);
  455.         Channel ch2 = new Channel("I Love You Venice", 60, 135);
  456.        
  457.         Subscriber sub1 = new Subscriber("Alan", 20, 40);
  458.         Subscriber sub2 = new Subscriber("Mark", 20, 40);
  459.         Monitor mon1 = new Monitor("Stat Sensor A", 30);
  460.        
  461.         ch1.follow(sub1);
  462.         ch1.follow(mon1);
  463.         ch1.follow(sub2);
  464.        
  465.         ch2.follow(mon1);
  466.         ch2.follow(sub2);
  467.         ch2.follow(sub1);
  468.        
  469.        
  470.         ch1.releaseANewVideo("Jazz Piano Radio");
  471.         ch2.releaseANewVideo("Baroque Live Music 24/7");
  472.        
  473.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  474.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  475.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  476.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  477.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM, I Love You Venice].", mon1.toString());
  478.        
  479.         /*
  480.          * Subscriber `sub1` watched Jazz Piano Radio for 40 minutes.
  481.          */
  482.         sub1.watch("Jazz Piano Radio", 40);
  483.        
  484.         /*
  485.          * Statistics for the watched video is updated for `mon1`.
  486.          * For the average watch time, display with two digits after the decimal point.
  487.          */
  488.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 1, max watch time: 40, avg watch time: 40.00}, I Love You Venice].", mon1.toString());
  489.         /* All other channels and subscribers remain unchanged. */
  490.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark].", ch1.toString());
  491.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  492.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  493.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  494.        
  495.         Monitor mon2 = new Monitor("Stat Sensor B", 30);
  496.         assertEquals("Monitor Stat Sensor B follows no channels.", mon2.toString());
  497.        
  498.         /*
  499.          * Let `mon2` start following `ch1`, meaning that
  500.          *  its statistics only covers the watch times happening from now on.
  501.          */
  502.         ch1.follow(mon2);
  503.         assertEquals("Monitor Stat Sensor B follows [Cafe Music BGM].", mon2.toString());
  504.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark, Monitor Stat Sensor B].", ch1.toString());
  505.        
  506.         /*
  507.          * Subscriber `sub2` watched Jazz Piano Radio for 30 minutes.
  508.          */
  509.         sub2.watch("Jazz Piano Radio", 30);
  510.  
  511.         /*
  512.          * Statistics for the watched video is updated for `mon1` and `mon2`.
  513.          */
  514.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 2, max watch time: 40, avg watch time: 35.00}, I Love You Venice].", mon1.toString());
  515.         assertEquals("Monitor Stat Sensor B follows [Cafe Music BGM {#views: 1, max watch time: 30, avg watch time: 30.00}].", mon2.toString());
  516.         /* All other channels and subscribers remain unchanged. */
  517.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark, Monitor Stat Sensor B].", ch1.toString());
  518.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  519.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  520.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  521.        
  522.         /*
  523.          * Subscriber `sub1` watched Jazz Piano Radio again for 15 minutes.
  524.          */
  525.         sub2.watch("Jazz Piano Radio", 15);
  526.        
  527.         /*
  528.          * Statistics for the watched video is updated for `mon1` and `mon2`.
  529.          */
  530.         assertEquals("Monitor Stat Sensor A follows [Cafe Music BGM {#views: 3, max watch time: 40, avg watch time: 28.33}, I Love You Venice].", mon1.toString());
  531.         assertEquals("Monitor Stat Sensor B follows [Cafe Music BGM {#views: 2, max watch time: 30, avg watch time: 22.50}].", mon2.toString());
  532.         /* All other channels and subscribers remain unchanged. */
  533.         assertEquals("Cafe Music BGM released <Jazz Piano Radio> and is followed by [Subscriber Alan, Monitor Stat Sensor A, Subscriber Mark, Monitor Stat Sensor B].", ch1.toString());
  534.         assertEquals("I Love You Venice released <Baroque Live Music 24/7> and is followed by [Monitor Stat Sensor A, Subscriber Mark, Subscriber Alan].", ch2.toString());
  535.         assertEquals("Subscriber Alan follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub1.toString());
  536.         assertEquals("Subscriber Mark follows [Cafe Music BGM, I Love You Venice] and is recommended <Jazz Piano Radio, Baroque Live Music 24/7>.", sub2.toString());
  537.     }
  538.    
  539. }
Advertisement
Add Comment
Please, Sign In to add comment