Exemple #1
0
  public Min(Lesson lesson) {
    super(lesson);

    BatWorld myWorld = new ConsWorld("min");
    myWorld.addTest(VISIBLE, data(new int[] {1, 2, 3, 4}));
    myWorld.addTest(VISIBLE, data(new int[] {1, 1, 1}));
    myWorld.addTest(VISIBLE, data(new int[] {1, 2, 1, 3, 2}));
    myWorld.addTest(INVISIBLE, data(new int[] {2, 4, 6, 8, 10}));
    myWorld.addTest(INVISIBLE, data(new int[] {6}));

    templatePython(
        "min",
        new String[] {"RecList"},
        "def min(list):\n",
        "  ptr = list.tail\n"
            + "  v = list.head\n"
            + "  while ptr != None:\n"
            + "     if ptr.head < v:\n"
            + "        v = ptr.head\n"
            + "     ptr = ptr.tail\n"
            + "  return v\n");
    templateScala(
        "min",
        new String[] {"List[Int]"},
        "def min(l:List[Int]): Int = {\n",
        "  def min2(l:List[Int], v:Int): Int = {\n"
            + "    if (l==Nil) return v\n"
            + "    if (l.head < v) return min2(l.tail, l.head)\n"
            + "    return min2(l.tail, v)\n"
            + "  }\n"
            + "  return min2(l.tail, l.head)\n"
            + "}");
    setup(myWorld);
  }
Exemple #2
0
  public LoneTeen(Game game, Lesson lesson) {
    super(game, lesson);

    BatWorld myWorld = new BatWorld(game, "loneTeen");
    myWorld.addTest(VISIBLE, 13, 42);
    myWorld.addTest(VISIBLE, 21, 19);
    myWorld.addTest(VISIBLE, 13, 13);

    myWorld.addTest(INVISIBLE, 14, 20);
    myWorld.addTest(INVISIBLE, 20, 15);
    myWorld.addTest(INVISIBLE, 16, 17);
    myWorld.addTest(INVISIBLE, 16, 9);
    myWorld.addTest(INVISIBLE, 16, 18);
    myWorld.addTest(INVISIBLE, 13, 19);
    myWorld.addTest(INVISIBLE, 13, 20);
    myWorld.addTest(INVISIBLE, 6, 18);
    myWorld.addTest(INVISIBLE, 42, 13);
    myWorld.addTest(INVISIBLE, 42, 42);

    templatePython(
        "loneTeen",
        new String[] {"Int", "Int"},
        "def loneTeen(a, b):\n",
        "	teenA = a>12 and a<20\n"
            + "	teenB = b>12 and b<20\n"
            + "	return  (teenA and not teenB) or (teenB and not teenA)\n");
    templateScala(
        "loneTeen",
        new String[] {"Int", "Int"},
        "def loneTeen(a:Int, b:Int):Boolean = {\n",
        "	val teenA = a>12 && a<20\n"
            + "	val teenB = b>12 && b<20\n"
            + "	return  (teenA && !teenB) || (teenB && !teenA)\n"
            + "}");
    setup(myWorld);
  }
Exemple #3
0
  public RedTicket(Lesson lesson) {
    super(lesson);

    BatWorld myWorld = new BatWorld("redTicket");
    myWorld.addTest(VISIBLE, 2, 2, 2);
    myWorld.addTest(VISIBLE, 2, 2, 1);
    myWorld.addTest(VISIBLE, 0, 0, 0);
    myWorld.addTest(INVISIBLE, 2, 0, 0);
    myWorld.addTest(INVISIBLE, 1, 1, 1);
    myWorld.addTest(INVISIBLE, 1, 2, 1);
    myWorld.addTest(INVISIBLE, 1, 2, 0);
    myWorld.addTest(INVISIBLE, 0, 2, 2);
    myWorld.addTest(INVISIBLE, 1, 2, 2);
    myWorld.addTest(INVISIBLE, 0, 2, 0);
    myWorld.addTest(INVISIBLE, 1, 1, 2);

    templatePython(
        "redTicket",
        "def redTicket(a, b, c):\n",
        "	if (a == b and b == c and c == 2):\n"
            + "		return 10\n"
            + "	elif (a == b and b == c):\n"
            + "		return 5\n"
            + "	elif (b != a and c != a):\n"
            + "		return 1\n"
            + "	else:\n"
            + "		return 0\n");
    templateScala(
        "redTicket",
        new String[] {"Int", "Int", "Int"},
        "def redTicket(a:Int, b:Int, c:Int):Int = {\n",
        "	if (a == b && b == c && c == 2)\n"
            + "		return 10\n"
            + "	else if (a == b && b == c)\n"
            + "		return 5\n"
            + "	else if (b != a && c != a)\n"
            + "		return 1\n"
            + "	else\n"
            + "		return 0\n"
            + "}");
    setup(myWorld);
  }
Exemple #4
0
  public TeenSum(Lesson lesson) {
    super(lesson);

    BatWorld myWorld = new BatWorld("teenSum");
    myWorld.addTest(VISIBLE, 3, 4);
    myWorld.addTest(VISIBLE, 10, 13);
    myWorld.addTest(VISIBLE, 13, 2);
    myWorld.addTest(INVISIBLE, 3, 19);
    myWorld.addTest(INVISIBLE, 13, 13);
    myWorld.addTest(INVISIBLE, 10, 10);
    myWorld.addTest(INVISIBLE, 6, 14);
    myWorld.addTest(INVISIBLE, 15, 2);
    myWorld.addTest(INVISIBLE, 19, 19);
    myWorld.addTest(INVISIBLE, 19, 20);
    myWorld.addTest(INVISIBLE, 2, 18);
    myWorld.addTest(INVISIBLE, 12, 4);
    myWorld.addTest(INVISIBLE, 2, 20);
    myWorld.addTest(INVISIBLE, 2, 17);
    myWorld.addTest(INVISIBLE, 2, 16);
    myWorld.addTest(INVISIBLE, 6, 7);

    templatePython(
        "teenSum",
        "def teenSum(a, b):\n",
        "	if ((a >= 13 and a <= 19) or (b >= 13 and b <= 19)):\n"
            + "		return 19\n"
            + "	else:\n"
            + "		return a+b\n");
    templateScala(
        "teenSum",
        new String[] {"Int", "Int"},
        "def teenSum(a:Int, b:Int):Int = {\n",
        "	if ((a >= 13 && a <= 19) || (b >= 13 && b <= 19))\n"
            + "		return 19\n"
            + "	else\n"
            + "		return a+b\n"
            + "}");
    setup(myWorld);
  }
Exemple #5
0
  public LessBy10(Game game, Lesson lesson) {
    super(game, lesson);

    BatWorld myWorld = new BatWorld(game, "lessBy10");
    myWorld.addTest(VISIBLE, 1, 7, 11);
    myWorld.addTest(VISIBLE, 1, 7, 10);
    myWorld.addTest(VISIBLE, 11, 1, 7);
    myWorld.addTest(INVISIBLE, 10, 7, 1);
    myWorld.addTest(INVISIBLE, -10, 2, 2);
    myWorld.addTest(INVISIBLE, 2, 11, 11);
    myWorld.addTest(INVISIBLE, 3, 3, 30);
    myWorld.addTest(INVISIBLE, 3, 3, 3);
    myWorld.addTest(INVISIBLE, 10, 1, 11);
    myWorld.addTest(INVISIBLE, 10, 11, 1);
    myWorld.addTest(INVISIBLE, 10, 11, 2);
    myWorld.addTest(INVISIBLE, 3, 30, 3);
    myWorld.addTest(INVISIBLE, 2, 2, -8);
    myWorld.addTest(INVISIBLE, 2, 8, 12);

    templatePython(
        "lessBy10",
        new String[] {"Int", "Int", "Int"},
        "def lessBy10(a, b, c):\n",
        "	return ((a - b) >= 10) or ((b - a) >= 10) or ((b - c) >= 10) or ((c - b) >= 10) or ((a - c) >= 10) or ((c - a) >= 10)\n");
    templateScala(
        "lessBy10",
        new String[] {"Int", "Int", "Int"},
        "def lessBy10(a:Int, b:Int, c:Int):Boolean = {\n",
        "	return ((a - b) >= 10) || ((b - a) >= 10) || ((b - c) >= 10) || ((c - b) >= 10) || ((a - c) >= 10) || ((c - a) >= 10)\n"
            + "}");
    setup(myWorld);
  }
Exemple #6
0
  public Last2(Lesson lesson) {
    super(lesson);

    BatWorld myWorld = new BatWorld("last2");
    myWorld.addTest(VISIBLE, "hixxhi");
    myWorld.addTest(VISIBLE, "xaxxaxaxx");
    myWorld.addTest(VISIBLE, "axxxaaxx");
    myWorld.addTest(INVISIBLE, "xxaxxaxxaxx");
    myWorld.addTest(INVISIBLE, "xaxaxaxx");
    myWorld.addTest(INVISIBLE, "13121312");
    myWorld.addTest(INVISIBLE, "11212");
    myWorld.addTest(INVISIBLE, "13121311");
    myWorld.addTest(INVISIBLE, "1717171");
    myWorld.addTest(INVISIBLE, "hi");
    myWorld.addTest(INVISIBLE, "h");
    myWorld.addTest(INVISIBLE, "");

    templatePython(
        "last2",
        "def last2(str):\n",
        "  l = len(str)\n"
            + "  if l < 2:\n"
            + "    return 0\n"
            + "  end = str[l-2:l]\n"
            + "  count = 0\n"
            + "  for i in range(len(str)-2):\n"
            + "    if str[i:i+2] == end:\n"
            + "      count += 1\n"
            + "  return count\n");
    templateScala(
        "last2",
        new String[] {"String"},
        "def last2(str:String):Int = {\n",
        "  val l = str.length\n"
            + "  if (l < 2)\n"
            + "    return 0\n"
            + "  val end = str.substring(l-2,l)\n"
            + "  var count = 0\n"
            + "  for (i <- 0 to str.length-3)\n"
            + "    if (str.substring(i,i+2) == end)\n"
            + "      count += 1\n"
            + "  return count\n"
            + "}");
    setup(myWorld);
  }