Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. package Zad2;
  2.  
  3. import junit.framework.TestCase;
  4.  
  5. public class TestZbior extends TestCase
  6. {
  7.  
  8.     private Zbior z;
  9.     protected void setUp() throws Exception
  10.     {
  11.         super.setUp();
  12.         z = new Zbior();
  13.         z.dodaj(5);
  14.         z.dodaj(3);
  15.         z.dodaj(6);
  16.         z.dodaj(3);
  17.         z.dodaj(8);
  18.         z.dodaj(7);
  19.     }
  20.  
  21.     protected void tearDown() throws Exception
  22.     {
  23.         super.tearDown();
  24.     }
  25.  
  26.     public void testDodaj()
  27.     {
  28.         z.dodaj(8);
  29.         assertEquals(8, z.zbior[ z.roz-1 ]);
  30.         z.dodaj(3);
  31.         assertEquals(3, z.zbior[ z.roz-1 ]);
  32.     }
  33.  
  34.     public void testUsun() throws NotExistsInStackException
  35.     {
  36.         try
  37.         {
  38.             z.usun(90);
  39.         }
  40.         catch( NotExistsInStackException e )
  41.         {
  42.             System.err.println( e.getMessage() );
  43.         }
  44.        
  45.         try
  46.         {
  47.             z.usun(3);
  48.         }
  49.         catch( NotExistsInStackException e )
  50.         {
  51.             System.err.println( e.getMessage() );
  52.         }
  53.        
  54.         assertEquals( z.zbior[1], 6); // sprawdzaneio po usunieciu 3
  55.         assertEquals( z.zbior[2], 8); // jw.
  56.         assertEquals( z.zbior[3], 7); // jw.
  57.         assertEquals( z.zbior[4], 0); // jw.
  58.     }
  59.  
  60.  
  61.     public void testPobierzSume()
  62.     {
  63.         assertEquals( 32, z.pobierzSume() );
  64.     }
  65.  
  66.     public void testIloraz_elem() throws DivisionByZeroException
  67.     {
  68.         try
  69.         {
  70.             z.iloraz_elem(4);
  71.             assertEquals( 1, z.zbior[0] );
  72.             assertEquals( 0, z.zbior[1] );
  73.             assertEquals( 2, z.zbior[4] );
  74.             assertEquals( 0, z.zbior[22] );
  75.             z.iloraz_elem(0);
  76.         }
  77.         catch( DivisionByZeroException e )
  78.         {
  79.             System.err.println( e.getMessage() );
  80.         }
  81.     }
  82.  
  83.     public void testSprawdz()
  84.     {
  85.         assertTrue( z.sprawdz(5) );
  86.         assertFalse( z.sprawdz(72) );
  87.         assertFalse( z.sprawdz(2) );
  88.     }
  89.     public void testPobierz_rozmiar()
  90.     {
  91.         assertEquals( 6, z.pobierz_rozmiar() );
  92.     }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement