Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tester.Tester;
- interface IFunc<X, Y> {
- Y apply(X x);
- }
- // A function from Int -> Int that can be plotted on the cartesian plane
- abstract class Plottable implements IFunc<Integer, Integer> {
- // Does this function cover the origin? (does f(0) = 0?)
- boolean coversOrigin() {
- return ...;
- }
- }
- // f(x) = x
- class Identity extends Plottable {
- public Integer apply(Integer x) {
- return x;
- }
- }
- // f(x) = ax^2 + bx + c
- class Quadratic extends Plottable {
- int a;
- int b;
- int c;
- Quadratic(int a, int b, int c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
- public Integer apply(Integer x) {
- return this.a * x * x + this.b * x + this.c;
- }
- }
- class ExamplesPlottable {
- Plottable identity = new Identity();
- Plottable xSquared = new Quadratic(1, 0, 0);
- Plottable xSquaredPlusOne = new Quadratic(1, 0, 1);
- boolean testIdentity(Tester t) {
- return t.checkExpect(identity.apply(0), ?)
- && t.checkExpect(identity.apply(5), ?);
- }
- boolean testXSquared(Tester t) {
- return t.checkExpect(xSquared.apply(0), ?)
- && t.checkExpect(xSquared.apply(5), ?);
- }
- boolean testXSquaredPlusOne(Tester t) {
- return t.checkExpect(xSquaredPlusOne.apply(0), ?)
- && t.checkExpect(xSquaredPlusOne.apply(5), ?);
- }
- boolean testCoversOrigin(Tester t) {
- return t.checkExpect(identity.coversOrigin(), ?)
- && t.checkExpect(xSquared.coversOrigin(), ?)
- && t.checkExpect(xSquaredPlusOne.coversOrigin(), ?);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement