Results 1 to 2 of 2
  1. #1
    Morantyx's Avatar
    Morantyx is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Javaw.exe using 50% cpu when running testclass in JUnit

    Greetings all,

    I'm a student informatics from Belgium, I'm in my first year and at the moment we're writing simple classes that we have to correct by executing testclasses that we get from our teacher with JUnit. Now, I have a problem with one of the testclasses... When I try to execute it, javaw.exe starts using 50% of my cpu. Also there are 6 test-methods in the testclass and it seems that JUnit gets stuck at the 5th one. When I asked my teacher he had no clue at the moment how to solve this problem or just give an explanation why this problem occurs. My classes have no errors or warnings at all so it's only that one testclass that creates this problem. The project was to make a class to write fractions as 8/5, 7/10, ... and a class that makes a mathematician than can add 2 of those fractions together, multiply 2 of them, and make a fraction more simple (like change 85/5 to 17/1). It's the testclass for the mathematician-class that gives this problem.

    Could anyone tell me what I can change/improve in my teacher's testclass so it will work decently and so javaw.exe won't take half of my cpu ? I have added my 2 classes and my teacher's testclass. Thanks in advance.

    The two classes I've written :

    1) Breuk (fraction)

    package domainmodel;

    public class Breuk {
    private int teller;
    private int noemer;
    private double decimaalgetal;

    public Breuk() {
    setTeller(teller);
    if(noemer!=0){
    setNoemer(noemer);
    } else {
    setNoemer(1);
    }
    }

    public Breuk(int teller, int noemer) {
    if(teller!=0) {
    setTeller(teller);
    } else if(teller==0) {
    setTeller(0);
    }
    if(noemer!=0){
    setNoemer(noemer);
    } else if(noemer==0) {
    setNoemer(1);
    }
    }

    public void setTeller(int teller) {
    this.teller = teller;
    }

    public int getTeller() {
    return teller;
    }

    public void setNoemer(int noemer) {
    if(noemer!=0) {
    this.noemer = noemer;
    }
    }

    public int getNoemer() {
    return noemer;
    }

    public void setDecimaalGetal(double decimaalgetal) {
    decimaalgetal = getTeller()/getNoemer();
    }

    public double getDecimaalGetal() {
    return decimaalgetal;
    }

    public String toString() {

    return getTeller() + "/" + getNoemer();
    }
    }

    2) Rekenaar (mathematician)

    package domainmodel;

    public class Rekenaar {
    private String voornaam = "anonieme";
    private String naam = "persoon";

    public Rekenaar() {

    }

    public Rekenaar(String voornaam, String naam) {
    setVoornaam(voornaam);
    setNaam(naam);
    }
    public String getVoornaam() {
    return voornaam;
    }
    public void setVoornaam(String voornaam) {
    this.voornaam = voornaam;
    }
    public String getNaam() {
    return naam;
    }
    public void setNaam(String naam) {
    this.naam = naam;
    }

    public Breuk multiplyBreuken(Breuk br1, Breuk br2) {
    Breuk result = new Breuk();
    if(br1!=null && br2!=null) {
    result.setTeller(br1.getTeller()*br2.getTeller());
    result.setNoemer(br1.getNoemer()*br2.getNoemer());
    } else {
    result.setTeller(0);
    result.setNoemer(1);
    }
    return result;
    }

    public Breuk addBreuken(Breuk br1, Breuk br2) {
    Breuk result = new Breuk();
    if(br1!=null && br2!=null) {
    if(br1.getNoemer()!=br2.getNoemer()){
    result.setNoemer(br1.getNoemer()*br2.getNoemer());
    result.setTeller((br1.getTeller()*br2.getNoemer()) +(br2.getTeller()*br1.getNoemer()));
    } else {
    result.setNoemer(br1.getNoemer());
    result.setTeller(br1.getTeller()+br2.getTeller());
    }
    } else {
    result = null;
    }
    return result;
    }

    public void vereenvoudigBreuk(Breuk b) {
    if(b!=null) {
    int ggd = 0;
    int hulp = 0;
    if(b.getTeller()>b.getNoemer()){
    hulp = b.getTeller();
    while(hulp!=0 || hulp>b.getNoemer()) {
    hulp -= b.getNoemer();
    }
    if(hulp==0){
    ggd = b.getNoemer();
    } else {
    ggd = hulp;
    }
    b.setTeller(b.getTeller()/ggd);
    b.setNoemer(b.getNoemer()/ggd);
    }
    if(b.getTeller()<b.getNoemer()) {
    hulp = b.getNoemer();
    while(hulp!=0 || hulp>b.getTeller()) {
    hulp -= b.getTeller();
    }
    if(hulp==0) {
    ggd = b.getTeller();
    } else {
    ggd = hulp;
    }
    b.setTeller(b.getTeller()/ggd);
    b.setNoemer(b.getNoemer()/ggd);
    }
    }
    }
    }

    And this is the testclass that I got from my teacher :

    package domainmodel;
    import junit.framework.TestCase;

    public class RekenaarTest extends TestCase
    { private Breuk breuk2op3;
    private Breuk breuk3op4;
    private Breuk breuk50op85;
    private Rekenaar rekenaar;

    protected void setUp () {
    breuk2op3= new Breuk(2,3);
    breuk3op4= new Breuk(3,4);
    breuk50op85= new Breuk(50,85);
    rekenaar = new Rekenaar("a","0");
    }

    public void testAddBreuk () {
    Breuk breuk = rekenaar.addBreuken(breuk3op4,breuk2op3);
    assertEquals(17, breuk.getTeller());
    assertEquals(12, breuk.getNoemer());
    }

    public void testAddMetNullalsParameter () {
    Breuk breuk = rekenaar.addBreuken(breuk3op4,null);
    assertEquals(breuk, null);
    breuk = rekenaar.addBreuken(null,breuk2op3);
    assertEquals(breuk, null);
    breuk = rekenaar.addBreuken(null,null);
    assertEquals(breuk, null);
    }

    public void testMultBreuk () {
    Breuk breuk = rekenaar.multiplyBreuken(breuk3op4,breuk2op3);
    assertEquals(6, breuk.getTeller());
    assertEquals(12, breuk.getNoemer());
    }

    public void testMultBreukMetNullAlsParameter () {
    Breuk breuk = rekenaar.multiplyBreuken(breuk3op4,null);
    assertEquals(breuk, null);
    breuk = rekenaar.multiplyBreuken(null,breuk2op3);
    assertEquals(breuk, null);
    breuk = rekenaar.multiplyBreuken(null,null);
    assertEquals(breuk, null);
    }

    public void testVereenvoudig () {
    rekenaar.vereenvoudigBreuk(breuk50op85);
    assertEquals(10, breuk50op85.getTeller());
    assertEquals(17, breuk50op85.getNoemer());
    }

    public void testVereenvoudigMetNullAlsParameter () {
    Breuk breuk = null;
    rekenaar.vereenvoudigBreuk(null);
    assertEquals(breuk, null);
    }

    }

  2. #2
    Morantyx's Avatar
    Morantyx is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Re: Javaw.exe using 50% cpu when running testclass in JUnit

    My apologies for this thread. There was a neverending loop in my code unless one part of the fraction is a multiple of the other part. Sorry, I was too fast with complaining.

Similar Threads

  1. Replies: 1
    Last Post: 09-19-2011, 02:53 PM
  2. javaw cpu
    By trishtren in forum New To Java
    Replies: 1
    Last Post: 04-18-2011, 03:13 PM
  3. Replies: 0
    Last Post: 06-26-2009, 08:40 AM
  4. javaw.exe running jbroker.exe?????
    By fxRichard in forum Advanced Java
    Replies: 3
    Last Post: 05-12-2009, 12:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •