Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
Created February 27, 2012 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nixpulvis/1926289 to your computer and use it in GitHub Desktop.
Save nixpulvis/1926289 to your computer and use it in GitHub Desktop.
Simple Ciclic Data
import tester.Tester;
class Star {
String name;
Movie movie;
Star(String name){
this.name = name;
}
Star(String name, Movie movie){
this.name = name;
this.movie = movie;
this.movie.addStar(this);
}
public void addMovie(Movie movie){
this.movie = movie;
}
}
class Movie {
String title;
Star star;
Movie(String title){
this.title = title;
}
Movie(String title, Star star){
this.title = title;
this.star = star;
this.star.addMovie(this);
}
public void addStar(Star star){
this.star = star;
}
}
class Examples {
Movie m = new Movie("Harry Potter");
Star s = new Star("Harry", m);
public boolean testThis(Tester t){
return t.checkExpect(s.name, "Harry")
&& t.checkExpect(s.movie, m)
&& t.checkExpect(m.title, "Harry Potter")
&& t.checkExpect(m.star, s);
}
Star s2 = new Star("Mike");
Movie m2 = new Movie("Callout", s2);
public boolean testThis2(Tester t){
return t.checkExpect(s2.name, "Mike")
&& t.checkExpect(s2.movie, m2)
&& t.checkExpect(m2.title, "Callout")
&& t.checkExpect(m2.star, s2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment