daily pastebin goal
93%
SHARE
TWEET

testsbreakout

a guest Dec 23rd, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. import data.Repositories;
  8. import data.util.MySqlConnection;
  9. import domain.BCrypt;
  10. import domain.User;
  11. import game.GameState;
  12. import java.sql.SQLException;
  13. import org.junit.After;
  14. import org.junit.AfterClass;
  15. import org.junit.Before;
  16. import org.junit.BeforeClass;
  17. import org.junit.Test;
  18. import static org.junit.Assert.*;
  19. import utils.AdminException;
  20. import java.sql.Connection;
  21. import models.Ball;
  22. import models.Brick;
  23. import models.Color;
  24. import models.Player;
  25. import models.powers.KeyboardInverter;
  26. import models.powers.Power;
  27. import models.powers.Resizer;
  28. import models.powers.ScoreMultiplier;
  29.  
  30. /**
  31.  *
  32.  * @author nicokrekelberg
  33.  */
  34. public class TestBreakout {
  35.  
  36.     public TestBreakout() {
  37.     }
  38.  
  39.    
  40.    
  41.     @Test
  42.     public void testConnection() throws SQLException {
  43.         try (Connection con = MySqlConnection.getConnection();) {
  44.         } catch (AdminException ex) {
  45.             fail("Failed to make connection");
  46.         }
  47.     }
  48.    
  49.    
  50.     @Test
  51.     public void testBCryptCorrect(){
  52.         String username = "test";
  53.         String password = "passwordtest";
  54.         String hash = BCrypt.hashpw(password, BCrypt.gensalt(10));
  55.         User registered = new User(username, hash);
  56.         User login = new User("test", "passwordtest");
  57.         if (BCrypt.checkpw(login.getPassword(), registered.getPassword())) {
  58.             assertTrue(true);
  59.         } else {
  60.             assertFalse(true);
  61.         }
  62.     }
  63.  
  64.    
  65.     @Test
  66.     public void testBCryptIncorrect(){
  67.         String username = "test";
  68.         String password = "passwordtest";
  69.         String hash = BCrypt.hashpw(password, BCrypt.gensalt(10));
  70.         User registered = new User(username, hash);
  71.         User login = new User("test", "incorrectpassword");
  72.         if (BCrypt.checkpw(login.getPassword(), registered.getPassword())) {
  73.             assertFalse(true);
  74.         } else {
  75.             assertTrue(true);
  76.         }
  77.     }
  78.    
  79.    
  80.     @Test
  81.     public void testKeyboardInverter(){
  82.         GameState game = new GameState(600, 500);
  83.         Power p = new KeyboardInverter(600, 500);
  84.         p.activate(game);
  85.         assertEquals(game.getKeyboard().getLeft(), 68);
  86.         assertEquals(game.getKeyboard().getRight(), 81);
  87.         assertEquals(game.getKeyboard().getLefttwo(), 39);
  88.         assertEquals(game.getKeyboard().getRighttwo(), 37);
  89.        
  90.         p.disable(game);
  91.         assertEquals(game.getKeyboard().getLeft(), 81);
  92.         assertEquals(game.getKeyboard().getRight(), 68);
  93.         assertEquals(game.getKeyboard().getLefttwo(), 37);
  94.         assertEquals(game.getKeyboard().getRighttwo(), 39);
  95.     }
  96.  
  97.    
  98.     @Test
  99.     public void testPlayerResizer(){
  100.         GameState game = new GameState(600,500);
  101.         game.addPlayer(new Player(0.50, 0.90, 0.2, 0.01, "rgba(255, 255, 0, .5)"));
  102.         double beforeResizer = game.getPlayers().get(0).getW(); // 0.2
  103.         Power p = new Resizer(600, 500, 2);
  104.         p.activate(game); // 0.2 * 2
  105.         assertEquals(beforeResizer * 2, game.getPlayers().get(0).getW(), 0);
  106.         p.disable(game);
  107.         assertEquals(beforeResizer, game.getPlayers().get(0).getW(), 0);
  108.     }
  109.    
  110.     @Test
  111.     public void testScoreMultiplier(){
  112.         Brick b = new Brick(0.05, new Color(0, 255, 0), 1000, 1, 1, 3, 0); //worth 1000 points
  113.         GameState game = new GameState(600,500);
  114.         b.onDeath(game); // TotalPoints = 0 + 1000 = 1000
  115.         assertEquals(1000, game.getTotalPoints());
  116.        
  117.         Power p = new ScoreMultiplier(600, 500, 2);
  118.         p.activate(game);
  119.         b.onDeath(game);// TotalPoints = 1000 + (1000 * 2) = 3000
  120.         assertEquals(3000, game.getTotalPoints());
  121.        
  122.         p.disable(game);
  123.         b.onDeath(game);// Totalpoints = 3000 + 1000
  124.         assertEquals(4000, game.getTotalPoints());
  125.        
  126.     }
  127.    
  128.     @Test
  129.     public void testStackPowers(){
  130.         Brick b = new Brick(0.05, new Color(0, 255, 0), 1000, 1, 1, 3, 0); //worth 1000 points
  131.         GameState game = new GameState(600,500);
  132.         game.addPlayer(new Player(0.50, 0.90, 0.2, 0.01, "rgba(255, 255, 0, .5)"));
  133.         double beforeResizer = game.getPlayers().get(0).getW(); // 0.2
  134.        
  135.         b.onDeath(game); // TotalPoints = 0 + 1000 = 1000
  136.         assertEquals(1000, game.getTotalPoints());
  137.        
  138.         Power p = new ScoreMultiplier(600, 500, 2);
  139.         p.activate(game);
  140.         b.onDeath(game); // TotalPoints = 1000 + (1000 * 2) = 3000
  141.         assertEquals(3000, game.getTotalPoints());
  142.        
  143.        
  144.         assertEquals(beforeResizer, 0.2, 0);// not resized
  145.         p = new Resizer(600, 500, 2);
  146.         p.activate(game); // Do resizer: 0.4
  147.         b.onDeath(game); // Should still do scoreMultiplier = 3000 + (1000 * 2)
  148.         assertEquals(5000, game.getTotalPoints());
  149.         assertEquals(beforeResizer * 2, game.getPlayers().get(0).getW(), 0);
  150.     }
  151.    
  152.    
  153.    
  154.     @Test
  155.     public void testBaller(){
  156.         GameState game = new GameState(600,500);
  157.         Player player = new Player(0.50, 0.90, 0.2, 0.01, "rgba(255, 255, 0, .5)");
  158.         game.addPlayer(player);
  159.         Ball ball = new Ball(game.getPlayers().get(0).getCenterPointX(), game.getPlayers().get(0).getCenterPointY() - (game.getPlayers().get(0).getH() / 2), 0.01, "rgba(127, 255, 212, .5)");
  160.  
  161.         for(int i = 0; i<10;i++){
  162.             assertEquals(game.getBalls().size(), i);
  163.             game.addBall(ball);
  164.             assertEquals(game.getBalls().size(), i+1);
  165.         }
  166.     }
  167.    
  168.  
  169.    
  170.     @Test
  171.     public void TestLostABall(){
  172.         GameState game = new GameState(600,500);
  173.         Player player = new Player(0.50, 0.90, 0.2, -5, "rgba(255, 255, 0, .5)");
  174.         game.addPlayer(player);
  175.         Ball ball = new Ball(0.9, 2, 0.01, "rgba(127, 255, 212, .5)");
  176.         game.addBall(ball);
  177.        
  178.         assertEquals(game.getBalls().size(), 1);
  179.        
  180.         ball.move(game);
  181.         if (ball.dead) {
  182.                 game.getBalls().remove(0);
  183.                 if (game.getBalls().size() == 0 && game.getLives() == 0) {
  184.                     game.setAllive(false);
  185.                 }
  186.             }
  187.        
  188.         assertEquals(game.getBalls().size(), 0);
  189.     }
  190.    
  191.    
  192.    
  193.     @Test
  194.     public void TestLoseTenBalls(){
  195.         GameState game = new GameState(600,500);
  196.         Player player = new Player(0.50, 0.90, 0.2, -5, "rgba(255, 255, 0, .5)");
  197.         game.addPlayer(player);
  198.         Ball ball = new Ball(0.9, 2, 0.01, "rgba(127, 255, 212, .5)");
  199.         for(int i = 0; i<10; i++){
  200.             game.addBall(ball);
  201.         }
  202.        
  203.         assertEquals(game.getBalls().size(), 10);
  204.        
  205.         ball.move(game);
  206.         for(int i = 0; i<10; i++){
  207.             if (ball.dead) {
  208.                 game.getBalls().remove(0);
  209.                 if (game.getBalls().size() == 0 && game.getLives() == 0) {
  210.                     game.setAllive(false);
  211.                 }
  212.             }
  213.         }
  214.         assertEquals(game.getBalls().size(), 0);
  215.     }
  216.    
  217. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top