Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Zad2;
- import junit.framework.TestCase;
- public class TestZbior extends TestCase
- {
- private Zbior z;
- protected void setUp() throws Exception
- {
- super.setUp();
- z = new Zbior();
- z.dodaj(5);
- z.dodaj(3);
- z.dodaj(6);
- z.dodaj(3);
- z.dodaj(8);
- z.dodaj(7);
- }
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
- public void testDodaj()
- {
- z.dodaj(8);
- assertEquals(8, z.zbior[ z.roz-1 ]);
- z.dodaj(3);
- assertEquals(3, z.zbior[ z.roz-1 ]);
- }
- public void testUsun() throws NotExistsInStackException
- {
- try
- {
- z.usun(90);
- }
- catch( NotExistsInStackException e )
- {
- System.err.println( e.getMessage() );
- }
- try
- {
- z.usun(3);
- }
- catch( NotExistsInStackException e )
- {
- System.err.println( e.getMessage() );
- }
- assertEquals( z.zbior[1], 6); // sprawdzaneio po usunieciu 3
- assertEquals( z.zbior[2], 8); // jw.
- assertEquals( z.zbior[3], 7); // jw.
- assertEquals( z.zbior[4], 0); // jw.
- }
- public void testPobierzSume()
- {
- assertEquals( 32, z.pobierzSume() );
- }
- public void testIloraz_elem() throws DivisionByZeroException
- {
- try
- {
- z.iloraz_elem(4);
- assertEquals( 1, z.zbior[0] );
- assertEquals( 0, z.zbior[1] );
- assertEquals( 2, z.zbior[4] );
- assertEquals( 0, z.zbior[22] );
- z.iloraz_elem(0);
- }
- catch( DivisionByZeroException e )
- {
- System.err.println( e.getMessage() );
- }
- }
- public void testSprawdz()
- {
- assertTrue( z.sprawdz(5) );
- assertFalse( z.sprawdz(72) );
- assertFalse( z.sprawdz(2) );
- }
- public void testPobierz_rozmiar()
- {
- assertEquals( 6, z.pobierz_rozmiar() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement