mardi 2 janvier 2018

JUNIT testing Math.random

Im stuck on testing the findRandom method. This is the code im testing:

package leah012; public class Bournemouth {

public static String[] bison;


    String AuthorQuote = "Experience: that most brutal of teachers. But you learn. My God do you learn.";
    String Author = "C.S. Lewis";


        public Bournemouth(String author, String authorQuote) {
        this.AuthorQuote = authorQuote;
        this.Author = author;
      }


          public String getAuthor() {
            return Author;
          }

          public void setAuthor(String author) {
            this.Author = author;
          }

          public String getAuthorQuote() {
            return AuthorQuote;
          }


          public void setAuthorQuote(String authorQuote) {
            this.AuthorQuote = authorQuote;
          }


      public int FindRandom(){
          int index = (int) (Math.random() * (Bournemouth.bison.length / 3));
          String what = Bournemouth.bison[index * 3];
          String who = Bournemouth.bison[1 + index * 3];
           System.out.printf("%s said \"%s\"", who, what);

        return index;
      }


}

And this is what i have so far:

package leah012;

import static org.junit.Assert.*;

import org.junit.Test;

public class BournemouthTest {

  @SuppressWarnings("unlikely-arg-type")
@Test
  public void testBournemouth() {
    Bournemouth b = new Bournemouth(null, null);
    String author = "C.S. Lewis";
    String authorQuote = "Experience: that most brutal of teachers. But you learn. My God do you learn.";
    equals( b.getAuthorQuote());
    b.setAuthor(author);
    b.setAuthorQuote(authorQuote);
    equals( b.getAuthor());
    equals( b.getAuthorQuote());
  }

  public void checkRandomLength(){
      int word;
      String What;
      String Who;

      for (int i = 0; i < 1000; i++) {
          word = tester.FindRandom();

      }
  }

}

But i have no idea what im doing! :(

Can someone help me please?

Aucun commentaire:

Enregistrer un commentaire