From b8d4ef860970a4410d2439b7e43d9c4959ec14fa Mon Sep 17 00:00:00 2001 From: Seokhyun Lee <7948302+henrylee97@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:32:34 +0900 Subject: [PATCH] refactor(ocaml): refactoring ocaml-diff (#25) * refactor(ocaml): refactoring ocaml-diff * Update src.ml * Update src.ml * Update src.ml * fix: build command * fix: syntax error --------- Co-authored-by: sdw0316 --- OCaml/diff-1/.dockerignore | 2 + OCaml/diff-1/Dockerfile | 6 ++ OCaml/diff-1/buggy/src.ml | 24 +++++++ OCaml/diff-1/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-1/buggy/testcases | 31 +++++++++ OCaml/diff-1/metadata.json | 12 ++++ OCaml/diff-10/.dockerignore | 2 + OCaml/diff-10/Dockerfile | 6 ++ OCaml/diff-10/buggy/src.ml | 32 ++++++++++ OCaml/diff-10/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-10/buggy/testcases | 31 +++++++++ OCaml/diff-10/metadata.json | 12 ++++ OCaml/diff-100/.dockerignore | 2 + OCaml/diff-100/Dockerfile | 6 ++ OCaml/diff-100/buggy/src.ml | 37 +++++++++++ OCaml/diff-100/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-100/buggy/testcases | 31 +++++++++ OCaml/diff-100/metadata.json | 12 ++++ OCaml/diff-11/.dockerignore | 2 + OCaml/diff-11/Dockerfile | 6 ++ OCaml/diff-11/buggy/src.ml | 32 ++++++++++ OCaml/diff-11/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-11/buggy/testcases | 31 +++++++++ OCaml/diff-11/metadata.json | 12 ++++ OCaml/diff-12/.dockerignore | 2 + OCaml/diff-12/Dockerfile | 6 ++ OCaml/diff-12/buggy/src.ml | 28 +++++++++ OCaml/diff-12/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-12/buggy/testcases | 31 +++++++++ OCaml/diff-12/metadata.json | 12 ++++ OCaml/diff-13/.dockerignore | 2 + OCaml/diff-13/Dockerfile | 6 ++ OCaml/diff-13/buggy/src.ml | 28 +++++++++ OCaml/diff-13/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-13/buggy/testcases | 31 +++++++++ OCaml/diff-13/metadata.json | 12 ++++ OCaml/diff-14/.dockerignore | 2 + OCaml/diff-14/Dockerfile | 6 ++ OCaml/diff-14/buggy/src.ml | 28 +++++++++ OCaml/diff-14/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-14/buggy/testcases | 31 +++++++++ OCaml/diff-14/metadata.json | 12 ++++ OCaml/diff-15/.dockerignore | 2 + OCaml/diff-15/Dockerfile | 6 ++ OCaml/diff-15/buggy/src.ml | 32 ++++++++++ OCaml/diff-15/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-15/buggy/testcases | 31 +++++++++ OCaml/diff-15/metadata.json | 12 ++++ OCaml/diff-16/.dockerignore | 2 + OCaml/diff-16/Dockerfile | 6 ++ OCaml/diff-16/buggy/src.ml | 43 +++++++++++++ OCaml/diff-16/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-16/buggy/testcases | 31 +++++++++ OCaml/diff-16/metadata.json | 12 ++++ OCaml/diff-17/.dockerignore | 2 + OCaml/diff-17/Dockerfile | 6 ++ OCaml/diff-17/buggy/src.ml | 43 +++++++++++++ OCaml/diff-17/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-17/buggy/testcases | 31 +++++++++ OCaml/diff-17/metadata.json | 12 ++++ OCaml/diff-18/.dockerignore | 2 + OCaml/diff-18/Dockerfile | 6 ++ OCaml/diff-18/buggy/src.ml | 30 +++++++++ OCaml/diff-18/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-18/buggy/testcases | 31 +++++++++ OCaml/diff-18/metadata.json | 12 ++++ OCaml/diff-19/.dockerignore | 2 + OCaml/diff-19/Dockerfile | 6 ++ OCaml/diff-19/buggy/src.ml | 34 ++++++++++ OCaml/diff-19/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-19/buggy/testcases | 31 +++++++++ OCaml/diff-19/metadata.json | 12 ++++ OCaml/diff-2/.dockerignore | 2 + OCaml/diff-2/Dockerfile | 6 ++ OCaml/diff-2/buggy/src.ml | 20 ++++++ OCaml/diff-2/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-2/buggy/testcases | 31 +++++++++ OCaml/diff-2/metadata.json | 12 ++++ OCaml/diff-20/.dockerignore | 2 + OCaml/diff-20/Dockerfile | 6 ++ OCaml/diff-20/buggy/src.ml | 24 +++++++ OCaml/diff-20/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-20/buggy/testcases | 31 +++++++++ OCaml/diff-20/metadata.json | 12 ++++ OCaml/diff-21/.dockerignore | 2 + OCaml/diff-21/Dockerfile | 6 ++ OCaml/diff-21/buggy/src.ml | 81 ++++++++++++++++++++++++ OCaml/diff-21/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-21/buggy/testcases | 31 +++++++++ OCaml/diff-21/metadata.json | 12 ++++ OCaml/diff-22/.dockerignore | 2 + OCaml/diff-22/Dockerfile | 6 ++ OCaml/diff-22/buggy/src.ml | 79 +++++++++++++++++++++++ OCaml/diff-22/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-22/buggy/testcases | 31 +++++++++ OCaml/diff-22/metadata.json | 12 ++++ OCaml/diff-23/.dockerignore | 2 + OCaml/diff-23/Dockerfile | 6 ++ OCaml/diff-23/buggy/src.ml | 50 +++++++++++++++ OCaml/diff-23/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-23/buggy/testcases | 31 +++++++++ OCaml/diff-23/metadata.json | 12 ++++ OCaml/diff-24/.dockerignore | 2 + OCaml/diff-24/Dockerfile | 6 ++ OCaml/diff-24/buggy/src.ml | 24 +++++++ OCaml/diff-24/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-24/buggy/testcases | 31 +++++++++ OCaml/diff-24/metadata.json | 12 ++++ OCaml/diff-25/.dockerignore | 2 + OCaml/diff-25/Dockerfile | 6 ++ OCaml/diff-25/buggy/src.ml | 59 +++++++++++++++++ OCaml/diff-25/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-25/buggy/testcases | 31 +++++++++ OCaml/diff-25/metadata.json | 12 ++++ OCaml/diff-26/.dockerignore | 2 + OCaml/diff-26/Dockerfile | 6 ++ OCaml/diff-26/buggy/src.ml | 56 +++++++++++++++++ OCaml/diff-26/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-26/buggy/testcases | 31 +++++++++ OCaml/diff-26/metadata.json | 12 ++++ OCaml/diff-27/.dockerignore | 2 + OCaml/diff-27/Dockerfile | 6 ++ OCaml/diff-27/buggy/src.ml | 112 +++++++++++++++++++++++++++++++++ OCaml/diff-27/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-27/buggy/testcases | 31 +++++++++ OCaml/diff-27/metadata.json | 12 ++++ OCaml/diff-28/.dockerignore | 2 + OCaml/diff-28/Dockerfile | 6 ++ OCaml/diff-28/buggy/src.ml | 57 +++++++++++++++++ OCaml/diff-28/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-28/buggy/testcases | 31 +++++++++ OCaml/diff-28/metadata.json | 12 ++++ OCaml/diff-29/.dockerignore | 2 + OCaml/diff-29/Dockerfile | 6 ++ OCaml/diff-29/buggy/src.ml | 59 +++++++++++++++++ OCaml/diff-29/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-29/buggy/testcases | 31 +++++++++ OCaml/diff-29/metadata.json | 12 ++++ OCaml/diff-3/.dockerignore | 2 + OCaml/diff-3/Dockerfile | 6 ++ OCaml/diff-3/buggy/src.ml | 29 +++++++++ OCaml/diff-3/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-3/buggy/testcases | 31 +++++++++ OCaml/diff-3/metadata.json | 12 ++++ OCaml/diff-30/.dockerignore | 2 + OCaml/diff-30/Dockerfile | 6 ++ OCaml/diff-30/buggy/src.ml | 32 ++++++++++ OCaml/diff-30/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-30/buggy/testcases | 31 +++++++++ OCaml/diff-30/metadata.json | 12 ++++ OCaml/diff-31/.dockerignore | 2 + OCaml/diff-31/Dockerfile | 6 ++ OCaml/diff-31/buggy/src.ml | 32 ++++++++++ OCaml/diff-31/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-31/buggy/testcases | 31 +++++++++ OCaml/diff-31/metadata.json | 12 ++++ OCaml/diff-32/.dockerignore | 2 + OCaml/diff-32/Dockerfile | 6 ++ OCaml/diff-32/buggy/src.ml | 8 +++ OCaml/diff-32/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-32/buggy/testcases | 31 +++++++++ OCaml/diff-32/metadata.json | 12 ++++ OCaml/diff-33/.dockerignore | 2 + OCaml/diff-33/Dockerfile | 6 ++ OCaml/diff-33/buggy/src.ml | 60 ++++++++++++++++++ OCaml/diff-33/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-33/buggy/testcases | 31 +++++++++ OCaml/diff-33/metadata.json | 12 ++++ OCaml/diff-34/.dockerignore | 2 + OCaml/diff-34/Dockerfile | 6 ++ OCaml/diff-34/buggy/src.ml | 32 ++++++++++ OCaml/diff-34/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-34/buggy/testcases | 31 +++++++++ OCaml/diff-34/metadata.json | 12 ++++ OCaml/diff-35/.dockerignore | 2 + OCaml/diff-35/Dockerfile | 6 ++ OCaml/diff-35/buggy/src.ml | 21 +++++++ OCaml/diff-35/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-35/buggy/testcases | 31 +++++++++ OCaml/diff-35/metadata.json | 12 ++++ OCaml/diff-36/.dockerignore | 2 + OCaml/diff-36/Dockerfile | 6 ++ OCaml/diff-36/buggy/src.ml | 54 ++++++++++++++++ OCaml/diff-36/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-36/buggy/testcases | 31 +++++++++ OCaml/diff-36/metadata.json | 12 ++++ OCaml/diff-37/.dockerignore | 2 + OCaml/diff-37/Dockerfile | 6 ++ OCaml/diff-37/buggy/src.ml | 51 +++++++++++++++ OCaml/diff-37/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-37/buggy/testcases | 31 +++++++++ OCaml/diff-37/metadata.json | 12 ++++ OCaml/diff-38/.dockerignore | 2 + OCaml/diff-38/Dockerfile | 6 ++ OCaml/diff-38/buggy/src.ml | 30 +++++++++ OCaml/diff-38/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-38/buggy/testcases | 31 +++++++++ OCaml/diff-38/metadata.json | 12 ++++ OCaml/diff-39/.dockerignore | 2 + OCaml/diff-39/Dockerfile | 6 ++ OCaml/diff-39/buggy/src.ml | 30 +++++++++ OCaml/diff-39/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-39/buggy/testcases | 31 +++++++++ OCaml/diff-39/metadata.json | 12 ++++ OCaml/diff-4/.dockerignore | 2 + OCaml/diff-4/Dockerfile | 6 ++ OCaml/diff-4/buggy/src.ml | 18 ++++++ OCaml/diff-4/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-4/buggy/testcases | 31 +++++++++ OCaml/diff-4/metadata.json | 12 ++++ OCaml/diff-40/.dockerignore | 2 + OCaml/diff-40/Dockerfile | 6 ++ OCaml/diff-40/buggy/src.ml | 34 ++++++++++ OCaml/diff-40/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-40/buggy/testcases | 31 +++++++++ OCaml/diff-40/metadata.json | 12 ++++ OCaml/diff-41/.dockerignore | 2 + OCaml/diff-41/Dockerfile | 6 ++ OCaml/diff-41/buggy/src.ml | 22 +++++++ OCaml/diff-41/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-41/buggy/testcases | 31 +++++++++ OCaml/diff-41/metadata.json | 12 ++++ OCaml/diff-42/.dockerignore | 2 + OCaml/diff-42/Dockerfile | 6 ++ OCaml/diff-42/buggy/src.ml | 8 +++ OCaml/diff-42/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-42/buggy/testcases | 31 +++++++++ OCaml/diff-42/metadata.json | 12 ++++ OCaml/diff-43/.dockerignore | 2 + OCaml/diff-43/Dockerfile | 6 ++ OCaml/diff-43/buggy/src.ml | 28 +++++++++ OCaml/diff-43/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-43/buggy/testcases | 31 +++++++++ OCaml/diff-43/metadata.json | 12 ++++ OCaml/diff-44/.dockerignore | 2 + OCaml/diff-44/Dockerfile | 6 ++ OCaml/diff-44/buggy/src.ml | 16 +++++ OCaml/diff-44/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-44/buggy/testcases | 31 +++++++++ OCaml/diff-44/metadata.json | 12 ++++ OCaml/diff-45/.dockerignore | 2 + OCaml/diff-45/Dockerfile | 6 ++ OCaml/diff-45/buggy/src.ml | 35 +++++++++++ OCaml/diff-45/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-45/buggy/testcases | 31 +++++++++ OCaml/diff-45/metadata.json | 12 ++++ OCaml/diff-46/.dockerignore | 2 + OCaml/diff-46/Dockerfile | 6 ++ OCaml/diff-46/buggy/src.ml | 34 ++++++++++ OCaml/diff-46/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-46/buggy/testcases | 31 +++++++++ OCaml/diff-46/metadata.json | 12 ++++ OCaml/diff-47/.dockerignore | 2 + OCaml/diff-47/Dockerfile | 6 ++ OCaml/diff-47/buggy/src.ml | 21 +++++++ OCaml/diff-47/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-47/buggy/testcases | 31 +++++++++ OCaml/diff-47/metadata.json | 12 ++++ OCaml/diff-48/.dockerignore | 2 + OCaml/diff-48/Dockerfile | 6 ++ OCaml/diff-48/buggy/src.ml | 24 +++++++ OCaml/diff-48/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-48/buggy/testcases | 31 +++++++++ OCaml/diff-48/metadata.json | 12 ++++ OCaml/diff-49/.dockerignore | 2 + OCaml/diff-49/Dockerfile | 6 ++ OCaml/diff-49/buggy/src.ml | 23 +++++++ OCaml/diff-49/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-49/buggy/testcases | 31 +++++++++ OCaml/diff-49/metadata.json | 12 ++++ OCaml/diff-5/.dockerignore | 2 + OCaml/diff-5/Dockerfile | 6 ++ OCaml/diff-5/buggy/src.ml | 45 +++++++++++++ OCaml/diff-5/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-5/buggy/testcases | 31 +++++++++ OCaml/diff-5/metadata.json | 12 ++++ OCaml/diff-50/.dockerignore | 2 + OCaml/diff-50/Dockerfile | 6 ++ OCaml/diff-50/buggy/src.ml | 23 +++++++ OCaml/diff-50/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-50/buggy/testcases | 31 +++++++++ OCaml/diff-50/metadata.json | 12 ++++ OCaml/diff-51/.dockerignore | 2 + OCaml/diff-51/Dockerfile | 6 ++ OCaml/diff-51/buggy/src.ml | 17 +++++ OCaml/diff-51/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-51/buggy/testcases | 31 +++++++++ OCaml/diff-51/metadata.json | 12 ++++ OCaml/diff-52/.dockerignore | 2 + OCaml/diff-52/Dockerfile | 6 ++ OCaml/diff-52/buggy/src.ml | 28 +++++++++ OCaml/diff-52/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-52/buggy/testcases | 31 +++++++++ OCaml/diff-52/metadata.json | 12 ++++ OCaml/diff-53/.dockerignore | 2 + OCaml/diff-53/Dockerfile | 6 ++ OCaml/diff-53/buggy/src.ml | 63 +++++++++++++++++++ OCaml/diff-53/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-53/buggy/testcases | 31 +++++++++ OCaml/diff-53/metadata.json | 12 ++++ OCaml/diff-54/.dockerignore | 2 + OCaml/diff-54/Dockerfile | 6 ++ OCaml/diff-54/buggy/src.ml | 29 +++++++++ OCaml/diff-54/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-54/buggy/testcases | 31 +++++++++ OCaml/diff-54/metadata.json | 12 ++++ OCaml/diff-55/.dockerignore | 2 + OCaml/diff-55/Dockerfile | 6 ++ OCaml/diff-55/buggy/src.ml | 24 +++++++ OCaml/diff-55/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-55/buggy/testcases | 31 +++++++++ OCaml/diff-55/metadata.json | 12 ++++ OCaml/diff-56/.dockerignore | 2 + OCaml/diff-56/Dockerfile | 6 ++ OCaml/diff-56/buggy/src.ml | 28 +++++++++ OCaml/diff-56/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-56/buggy/testcases | 31 +++++++++ OCaml/diff-56/metadata.json | 12 ++++ OCaml/diff-57/.dockerignore | 2 + OCaml/diff-57/Dockerfile | 6 ++ OCaml/diff-57/buggy/src.ml | 47 ++++++++++++++ OCaml/diff-57/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-57/buggy/testcases | 31 +++++++++ OCaml/diff-57/metadata.json | 12 ++++ OCaml/diff-58/.dockerignore | 2 + OCaml/diff-58/Dockerfile | 6 ++ OCaml/diff-58/buggy/src.ml | 26 ++++++++ OCaml/diff-58/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-58/buggy/testcases | 31 +++++++++ OCaml/diff-58/metadata.json | 12 ++++ OCaml/diff-59/.dockerignore | 2 + OCaml/diff-59/Dockerfile | 6 ++ OCaml/diff-59/buggy/src.ml | 17 +++++ OCaml/diff-59/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-59/buggy/testcases | 31 +++++++++ OCaml/diff-59/metadata.json | 12 ++++ OCaml/diff-6/.dockerignore | 2 + OCaml/diff-6/Dockerfile | 6 ++ OCaml/diff-6/buggy/src.ml | 23 +++++++ OCaml/diff-6/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-6/buggy/testcases | 31 +++++++++ OCaml/diff-6/metadata.json | 12 ++++ OCaml/diff-60/.dockerignore | 2 + OCaml/diff-60/Dockerfile | 6 ++ OCaml/diff-60/buggy/src.ml | 20 ++++++ OCaml/diff-60/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-60/buggy/testcases | 31 +++++++++ OCaml/diff-60/metadata.json | 12 ++++ OCaml/diff-61/.dockerignore | 2 + OCaml/diff-61/Dockerfile | 6 ++ OCaml/diff-61/buggy/src.ml | 23 +++++++ OCaml/diff-61/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-61/buggy/testcases | 31 +++++++++ OCaml/diff-61/metadata.json | 12 ++++ OCaml/diff-62/.dockerignore | 2 + OCaml/diff-62/Dockerfile | 6 ++ OCaml/diff-62/buggy/src.ml | 34 ++++++++++ OCaml/diff-62/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-62/buggy/testcases | 31 +++++++++ OCaml/diff-62/metadata.json | 12 ++++ OCaml/diff-63/.dockerignore | 2 + OCaml/diff-63/Dockerfile | 6 ++ OCaml/diff-63/buggy/src.ml | 29 +++++++++ OCaml/diff-63/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-63/buggy/testcases | 31 +++++++++ OCaml/diff-63/metadata.json | 12 ++++ OCaml/diff-64/.dockerignore | 2 + OCaml/diff-64/Dockerfile | 6 ++ OCaml/diff-64/buggy/src.ml | 24 +++++++ OCaml/diff-64/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-64/buggy/testcases | 31 +++++++++ OCaml/diff-64/metadata.json | 12 ++++ OCaml/diff-65/.dockerignore | 2 + OCaml/diff-65/Dockerfile | 6 ++ OCaml/diff-65/buggy/src.ml | 29 +++++++++ OCaml/diff-65/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-65/buggy/testcases | 31 +++++++++ OCaml/diff-65/metadata.json | 12 ++++ OCaml/diff-66/.dockerignore | 2 + OCaml/diff-66/Dockerfile | 6 ++ OCaml/diff-66/buggy/src.ml | 22 +++++++ OCaml/diff-66/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-66/buggy/testcases | 31 +++++++++ OCaml/diff-66/metadata.json | 12 ++++ OCaml/diff-67/.dockerignore | 2 + OCaml/diff-67/Dockerfile | 6 ++ OCaml/diff-67/buggy/src.ml | 39 ++++++++++++ OCaml/diff-67/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-67/buggy/testcases | 31 +++++++++ OCaml/diff-67/metadata.json | 12 ++++ OCaml/diff-68/.dockerignore | 2 + OCaml/diff-68/Dockerfile | 6 ++ OCaml/diff-68/buggy/src.ml | 35 +++++++++++ OCaml/diff-68/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-68/buggy/testcases | 31 +++++++++ OCaml/diff-68/metadata.json | 12 ++++ OCaml/diff-69/.dockerignore | 2 + OCaml/diff-69/Dockerfile | 6 ++ OCaml/diff-69/buggy/src.ml | 83 ++++++++++++++++++++++++ OCaml/diff-69/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-69/buggy/testcases | 31 +++++++++ OCaml/diff-69/metadata.json | 12 ++++ OCaml/diff-7/.dockerignore | 2 + OCaml/diff-7/Dockerfile | 6 ++ OCaml/diff-7/buggy/src.ml | 31 +++++++++ OCaml/diff-7/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-7/buggy/testcases | 31 +++++++++ OCaml/diff-7/metadata.json | 12 ++++ OCaml/diff-70/.dockerignore | 2 + OCaml/diff-70/Dockerfile | 6 ++ OCaml/diff-70/buggy/src.ml | 8 +++ OCaml/diff-70/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-70/buggy/testcases | 31 +++++++++ OCaml/diff-70/metadata.json | 12 ++++ OCaml/diff-71/.dockerignore | 2 + OCaml/diff-71/Dockerfile | 6 ++ OCaml/diff-71/buggy/src.ml | 23 +++++++ OCaml/diff-71/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-71/buggy/testcases | 31 +++++++++ OCaml/diff-71/metadata.json | 12 ++++ OCaml/diff-72/.dockerignore | 2 + OCaml/diff-72/Dockerfile | 6 ++ OCaml/diff-72/buggy/src.ml | 23 +++++++ OCaml/diff-72/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-72/buggy/testcases | 31 +++++++++ OCaml/diff-72/metadata.json | 12 ++++ OCaml/diff-73/.dockerignore | 2 + OCaml/diff-73/Dockerfile | 6 ++ OCaml/diff-73/buggy/src.ml | 15 +++++ OCaml/diff-73/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-73/buggy/testcases | 31 +++++++++ OCaml/diff-73/metadata.json | 12 ++++ OCaml/diff-74/.dockerignore | 2 + OCaml/diff-74/Dockerfile | 6 ++ OCaml/diff-74/buggy/src.ml | 8 +++ OCaml/diff-74/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-74/buggy/testcases | 31 +++++++++ OCaml/diff-74/metadata.json | 12 ++++ OCaml/diff-75/.dockerignore | 2 + OCaml/diff-75/Dockerfile | 6 ++ OCaml/diff-75/buggy/src.ml | 17 +++++ OCaml/diff-75/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-75/buggy/testcases | 31 +++++++++ OCaml/diff-75/metadata.json | 12 ++++ OCaml/diff-76/.dockerignore | 2 + OCaml/diff-76/Dockerfile | 6 ++ OCaml/diff-76/buggy/src.ml | 59 +++++++++++++++++ OCaml/diff-76/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-76/buggy/testcases | 31 +++++++++ OCaml/diff-76/metadata.json | 12 ++++ OCaml/diff-77/.dockerignore | 2 + OCaml/diff-77/Dockerfile | 6 ++ OCaml/diff-77/buggy/src.ml | 28 +++++++++ OCaml/diff-77/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-77/buggy/testcases | 31 +++++++++ OCaml/diff-77/metadata.json | 12 ++++ OCaml/diff-78/.dockerignore | 2 + OCaml/diff-78/Dockerfile | 6 ++ OCaml/diff-78/buggy/src.ml | 34 ++++++++++ OCaml/diff-78/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-78/buggy/testcases | 31 +++++++++ OCaml/diff-78/metadata.json | 12 ++++ OCaml/diff-79/.dockerignore | 2 + OCaml/diff-79/Dockerfile | 6 ++ OCaml/diff-79/buggy/src.ml | 33 ++++++++++ OCaml/diff-79/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-79/buggy/testcases | 31 +++++++++ OCaml/diff-79/metadata.json | 12 ++++ OCaml/diff-8/.dockerignore | 2 + OCaml/diff-8/Dockerfile | 6 ++ OCaml/diff-8/buggy/src.ml | 43 +++++++++++++ OCaml/diff-8/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-8/buggy/testcases | 31 +++++++++ OCaml/diff-8/metadata.json | 12 ++++ OCaml/diff-80/.dockerignore | 2 + OCaml/diff-80/Dockerfile | 6 ++ OCaml/diff-80/buggy/src.ml | 18 ++++++ OCaml/diff-80/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-80/buggy/testcases | 31 +++++++++ OCaml/diff-80/metadata.json | 12 ++++ OCaml/diff-81/.dockerignore | 2 + OCaml/diff-81/Dockerfile | 6 ++ OCaml/diff-81/buggy/src.ml | 24 +++++++ OCaml/diff-81/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-81/buggy/testcases | 31 +++++++++ OCaml/diff-81/metadata.json | 12 ++++ OCaml/diff-82/.dockerignore | 2 + OCaml/diff-82/Dockerfile | 6 ++ OCaml/diff-82/buggy/src.ml | 37 +++++++++++ OCaml/diff-82/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-82/buggy/testcases | 31 +++++++++ OCaml/diff-82/metadata.json | 12 ++++ OCaml/diff-83/.dockerignore | 2 + OCaml/diff-83/Dockerfile | 6 ++ OCaml/diff-83/buggy/src.ml | 80 +++++++++++++++++++++++ OCaml/diff-83/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-83/buggy/testcases | 31 +++++++++ OCaml/diff-83/metadata.json | 12 ++++ OCaml/diff-84/.dockerignore | 2 + OCaml/diff-84/Dockerfile | 6 ++ OCaml/diff-84/buggy/src.ml | 31 +++++++++ OCaml/diff-84/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-84/buggy/testcases | 31 +++++++++ OCaml/diff-84/metadata.json | 12 ++++ OCaml/diff-85/.dockerignore | 2 + OCaml/diff-85/Dockerfile | 6 ++ OCaml/diff-85/buggy/src.ml | 54 ++++++++++++++++ OCaml/diff-85/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-85/buggy/testcases | 31 +++++++++ OCaml/diff-85/metadata.json | 12 ++++ OCaml/diff-86/.dockerignore | 2 + OCaml/diff-86/Dockerfile | 6 ++ OCaml/diff-86/buggy/src.ml | 19 ++++++ OCaml/diff-86/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-86/buggy/testcases | 31 +++++++++ OCaml/diff-86/metadata.json | 12 ++++ OCaml/diff-87/.dockerignore | 2 + OCaml/diff-87/Dockerfile | 6 ++ OCaml/diff-87/buggy/src.ml | 23 +++++++ OCaml/diff-87/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-87/buggy/testcases | 31 +++++++++ OCaml/diff-87/metadata.json | 12 ++++ OCaml/diff-88/.dockerignore | 2 + OCaml/diff-88/Dockerfile | 6 ++ OCaml/diff-88/buggy/src.ml | 50 +++++++++++++++ OCaml/diff-88/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-88/buggy/testcases | 31 +++++++++ OCaml/diff-88/metadata.json | 12 ++++ OCaml/diff-89/.dockerignore | 2 + OCaml/diff-89/Dockerfile | 6 ++ OCaml/diff-89/buggy/src.ml | 38 +++++++++++ OCaml/diff-89/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-89/buggy/testcases | 31 +++++++++ OCaml/diff-89/metadata.json | 12 ++++ OCaml/diff-9/.dockerignore | 2 + OCaml/diff-9/Dockerfile | 6 ++ OCaml/diff-9/buggy/src.ml | 23 +++++++ OCaml/diff-9/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-9/buggy/testcases | 31 +++++++++ OCaml/diff-9/metadata.json | 12 ++++ OCaml/diff-90/.dockerignore | 2 + OCaml/diff-90/Dockerfile | 6 ++ OCaml/diff-90/buggy/src.ml | 31 +++++++++ OCaml/diff-90/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-90/buggy/testcases | 31 +++++++++ OCaml/diff-90/metadata.json | 12 ++++ OCaml/diff-91/.dockerignore | 2 + OCaml/diff-91/Dockerfile | 6 ++ OCaml/diff-91/buggy/src.ml | 26 ++++++++ OCaml/diff-91/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-91/buggy/testcases | 31 +++++++++ OCaml/diff-91/metadata.json | 12 ++++ OCaml/diff-92/.dockerignore | 2 + OCaml/diff-92/Dockerfile | 6 ++ OCaml/diff-92/buggy/src.ml | 13 ++++ OCaml/diff-92/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-92/buggy/testcases | 31 +++++++++ OCaml/diff-92/metadata.json | 12 ++++ OCaml/diff-93/.dockerignore | 2 + OCaml/diff-93/Dockerfile | 6 ++ OCaml/diff-93/buggy/src.ml | 24 +++++++ OCaml/diff-93/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-93/buggy/testcases | 31 +++++++++ OCaml/diff-93/metadata.json | 12 ++++ OCaml/diff-94/.dockerignore | 2 + OCaml/diff-94/Dockerfile | 6 ++ OCaml/diff-94/buggy/src.ml | 54 ++++++++++++++++ OCaml/diff-94/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-94/buggy/testcases | 31 +++++++++ OCaml/diff-94/metadata.json | 12 ++++ OCaml/diff-95/.dockerignore | 2 + OCaml/diff-95/Dockerfile | 6 ++ OCaml/diff-95/buggy/src.ml | 21 +++++++ OCaml/diff-95/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-95/buggy/testcases | 31 +++++++++ OCaml/diff-95/metadata.json | 12 ++++ OCaml/diff-96/.dockerignore | 2 + OCaml/diff-96/Dockerfile | 6 ++ OCaml/diff-96/buggy/src.ml | 26 ++++++++ OCaml/diff-96/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-96/buggy/testcases | 31 +++++++++ OCaml/diff-96/metadata.json | 12 ++++ OCaml/diff-97/.dockerignore | 2 + OCaml/diff-97/Dockerfile | 6 ++ OCaml/diff-97/buggy/src.ml | 39 ++++++++++++ OCaml/diff-97/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-97/buggy/testcases | 31 +++++++++ OCaml/diff-97/metadata.json | 12 ++++ OCaml/diff-98/.dockerignore | 2 + OCaml/diff-98/Dockerfile | 6 ++ OCaml/diff-98/buggy/src.ml | 23 +++++++ OCaml/diff-98/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-98/buggy/testcases | 31 +++++++++ OCaml/diff-98/metadata.json | 12 ++++ OCaml/diff-99/.dockerignore | 2 + OCaml/diff-99/Dockerfile | 6 ++ OCaml/diff-99/buggy/src.ml | 22 +++++++ OCaml/diff-99/buggy/test.ml | 61 ++++++++++++++++++ OCaml/diff-99/buggy/testcases | 31 +++++++++ OCaml/diff-99/metadata.json | 12 ++++ 600 files changed, 14560 insertions(+) create mode 100644 OCaml/diff-1/.dockerignore create mode 100644 OCaml/diff-1/Dockerfile create mode 100644 OCaml/diff-1/buggy/src.ml create mode 100644 OCaml/diff-1/buggy/test.ml create mode 100644 OCaml/diff-1/buggy/testcases create mode 100644 OCaml/diff-1/metadata.json create mode 100644 OCaml/diff-10/.dockerignore create mode 100644 OCaml/diff-10/Dockerfile create mode 100644 OCaml/diff-10/buggy/src.ml create mode 100644 OCaml/diff-10/buggy/test.ml create mode 100644 OCaml/diff-10/buggy/testcases create mode 100644 OCaml/diff-10/metadata.json create mode 100644 OCaml/diff-100/.dockerignore create mode 100644 OCaml/diff-100/Dockerfile create mode 100644 OCaml/diff-100/buggy/src.ml create mode 100644 OCaml/diff-100/buggy/test.ml create mode 100644 OCaml/diff-100/buggy/testcases create mode 100644 OCaml/diff-100/metadata.json create mode 100644 OCaml/diff-11/.dockerignore create mode 100644 OCaml/diff-11/Dockerfile create mode 100644 OCaml/diff-11/buggy/src.ml create mode 100644 OCaml/diff-11/buggy/test.ml create mode 100644 OCaml/diff-11/buggy/testcases create mode 100644 OCaml/diff-11/metadata.json create mode 100644 OCaml/diff-12/.dockerignore create mode 100644 OCaml/diff-12/Dockerfile create mode 100644 OCaml/diff-12/buggy/src.ml create mode 100644 OCaml/diff-12/buggy/test.ml create mode 100644 OCaml/diff-12/buggy/testcases create mode 100644 OCaml/diff-12/metadata.json create mode 100644 OCaml/diff-13/.dockerignore create mode 100644 OCaml/diff-13/Dockerfile create mode 100644 OCaml/diff-13/buggy/src.ml create mode 100644 OCaml/diff-13/buggy/test.ml create mode 100644 OCaml/diff-13/buggy/testcases create mode 100644 OCaml/diff-13/metadata.json create mode 100644 OCaml/diff-14/.dockerignore create mode 100644 OCaml/diff-14/Dockerfile create mode 100644 OCaml/diff-14/buggy/src.ml create mode 100644 OCaml/diff-14/buggy/test.ml create mode 100644 OCaml/diff-14/buggy/testcases create mode 100644 OCaml/diff-14/metadata.json create mode 100644 OCaml/diff-15/.dockerignore create mode 100644 OCaml/diff-15/Dockerfile create mode 100644 OCaml/diff-15/buggy/src.ml create mode 100644 OCaml/diff-15/buggy/test.ml create mode 100644 OCaml/diff-15/buggy/testcases create mode 100644 OCaml/diff-15/metadata.json create mode 100644 OCaml/diff-16/.dockerignore create mode 100644 OCaml/diff-16/Dockerfile create mode 100644 OCaml/diff-16/buggy/src.ml create mode 100644 OCaml/diff-16/buggy/test.ml create mode 100644 OCaml/diff-16/buggy/testcases create mode 100644 OCaml/diff-16/metadata.json create mode 100644 OCaml/diff-17/.dockerignore create mode 100644 OCaml/diff-17/Dockerfile create mode 100644 OCaml/diff-17/buggy/src.ml create mode 100644 OCaml/diff-17/buggy/test.ml create mode 100644 OCaml/diff-17/buggy/testcases create mode 100644 OCaml/diff-17/metadata.json create mode 100644 OCaml/diff-18/.dockerignore create mode 100644 OCaml/diff-18/Dockerfile create mode 100644 OCaml/diff-18/buggy/src.ml create mode 100644 OCaml/diff-18/buggy/test.ml create mode 100644 OCaml/diff-18/buggy/testcases create mode 100644 OCaml/diff-18/metadata.json create mode 100644 OCaml/diff-19/.dockerignore create mode 100644 OCaml/diff-19/Dockerfile create mode 100644 OCaml/diff-19/buggy/src.ml create mode 100644 OCaml/diff-19/buggy/test.ml create mode 100644 OCaml/diff-19/buggy/testcases create mode 100644 OCaml/diff-19/metadata.json create mode 100644 OCaml/diff-2/.dockerignore create mode 100644 OCaml/diff-2/Dockerfile create mode 100644 OCaml/diff-2/buggy/src.ml create mode 100644 OCaml/diff-2/buggy/test.ml create mode 100644 OCaml/diff-2/buggy/testcases create mode 100644 OCaml/diff-2/metadata.json create mode 100644 OCaml/diff-20/.dockerignore create mode 100644 OCaml/diff-20/Dockerfile create mode 100644 OCaml/diff-20/buggy/src.ml create mode 100644 OCaml/diff-20/buggy/test.ml create mode 100644 OCaml/diff-20/buggy/testcases create mode 100644 OCaml/diff-20/metadata.json create mode 100644 OCaml/diff-21/.dockerignore create mode 100644 OCaml/diff-21/Dockerfile create mode 100644 OCaml/diff-21/buggy/src.ml create mode 100644 OCaml/diff-21/buggy/test.ml create mode 100644 OCaml/diff-21/buggy/testcases create mode 100644 OCaml/diff-21/metadata.json create mode 100644 OCaml/diff-22/.dockerignore create mode 100644 OCaml/diff-22/Dockerfile create mode 100644 OCaml/diff-22/buggy/src.ml create mode 100644 OCaml/diff-22/buggy/test.ml create mode 100644 OCaml/diff-22/buggy/testcases create mode 100644 OCaml/diff-22/metadata.json create mode 100644 OCaml/diff-23/.dockerignore create mode 100644 OCaml/diff-23/Dockerfile create mode 100644 OCaml/diff-23/buggy/src.ml create mode 100644 OCaml/diff-23/buggy/test.ml create mode 100644 OCaml/diff-23/buggy/testcases create mode 100644 OCaml/diff-23/metadata.json create mode 100644 OCaml/diff-24/.dockerignore create mode 100644 OCaml/diff-24/Dockerfile create mode 100644 OCaml/diff-24/buggy/src.ml create mode 100644 OCaml/diff-24/buggy/test.ml create mode 100644 OCaml/diff-24/buggy/testcases create mode 100644 OCaml/diff-24/metadata.json create mode 100644 OCaml/diff-25/.dockerignore create mode 100644 OCaml/diff-25/Dockerfile create mode 100644 OCaml/diff-25/buggy/src.ml create mode 100644 OCaml/diff-25/buggy/test.ml create mode 100644 OCaml/diff-25/buggy/testcases create mode 100644 OCaml/diff-25/metadata.json create mode 100644 OCaml/diff-26/.dockerignore create mode 100644 OCaml/diff-26/Dockerfile create mode 100644 OCaml/diff-26/buggy/src.ml create mode 100644 OCaml/diff-26/buggy/test.ml create mode 100644 OCaml/diff-26/buggy/testcases create mode 100644 OCaml/diff-26/metadata.json create mode 100644 OCaml/diff-27/.dockerignore create mode 100644 OCaml/diff-27/Dockerfile create mode 100644 OCaml/diff-27/buggy/src.ml create mode 100644 OCaml/diff-27/buggy/test.ml create mode 100644 OCaml/diff-27/buggy/testcases create mode 100644 OCaml/diff-27/metadata.json create mode 100644 OCaml/diff-28/.dockerignore create mode 100644 OCaml/diff-28/Dockerfile create mode 100644 OCaml/diff-28/buggy/src.ml create mode 100644 OCaml/diff-28/buggy/test.ml create mode 100644 OCaml/diff-28/buggy/testcases create mode 100644 OCaml/diff-28/metadata.json create mode 100644 OCaml/diff-29/.dockerignore create mode 100644 OCaml/diff-29/Dockerfile create mode 100644 OCaml/diff-29/buggy/src.ml create mode 100644 OCaml/diff-29/buggy/test.ml create mode 100644 OCaml/diff-29/buggy/testcases create mode 100644 OCaml/diff-29/metadata.json create mode 100644 OCaml/diff-3/.dockerignore create mode 100644 OCaml/diff-3/Dockerfile create mode 100644 OCaml/diff-3/buggy/src.ml create mode 100644 OCaml/diff-3/buggy/test.ml create mode 100644 OCaml/diff-3/buggy/testcases create mode 100644 OCaml/diff-3/metadata.json create mode 100644 OCaml/diff-30/.dockerignore create mode 100644 OCaml/diff-30/Dockerfile create mode 100644 OCaml/diff-30/buggy/src.ml create mode 100644 OCaml/diff-30/buggy/test.ml create mode 100644 OCaml/diff-30/buggy/testcases create mode 100644 OCaml/diff-30/metadata.json create mode 100644 OCaml/diff-31/.dockerignore create mode 100644 OCaml/diff-31/Dockerfile create mode 100644 OCaml/diff-31/buggy/src.ml create mode 100644 OCaml/diff-31/buggy/test.ml create mode 100644 OCaml/diff-31/buggy/testcases create mode 100644 OCaml/diff-31/metadata.json create mode 100644 OCaml/diff-32/.dockerignore create mode 100644 OCaml/diff-32/Dockerfile create mode 100644 OCaml/diff-32/buggy/src.ml create mode 100644 OCaml/diff-32/buggy/test.ml create mode 100644 OCaml/diff-32/buggy/testcases create mode 100644 OCaml/diff-32/metadata.json create mode 100644 OCaml/diff-33/.dockerignore create mode 100644 OCaml/diff-33/Dockerfile create mode 100644 OCaml/diff-33/buggy/src.ml create mode 100644 OCaml/diff-33/buggy/test.ml create mode 100644 OCaml/diff-33/buggy/testcases create mode 100644 OCaml/diff-33/metadata.json create mode 100644 OCaml/diff-34/.dockerignore create mode 100644 OCaml/diff-34/Dockerfile create mode 100644 OCaml/diff-34/buggy/src.ml create mode 100644 OCaml/diff-34/buggy/test.ml create mode 100644 OCaml/diff-34/buggy/testcases create mode 100644 OCaml/diff-34/metadata.json create mode 100644 OCaml/diff-35/.dockerignore create mode 100644 OCaml/diff-35/Dockerfile create mode 100644 OCaml/diff-35/buggy/src.ml create mode 100644 OCaml/diff-35/buggy/test.ml create mode 100644 OCaml/diff-35/buggy/testcases create mode 100644 OCaml/diff-35/metadata.json create mode 100644 OCaml/diff-36/.dockerignore create mode 100644 OCaml/diff-36/Dockerfile create mode 100644 OCaml/diff-36/buggy/src.ml create mode 100644 OCaml/diff-36/buggy/test.ml create mode 100644 OCaml/diff-36/buggy/testcases create mode 100644 OCaml/diff-36/metadata.json create mode 100644 OCaml/diff-37/.dockerignore create mode 100644 OCaml/diff-37/Dockerfile create mode 100644 OCaml/diff-37/buggy/src.ml create mode 100644 OCaml/diff-37/buggy/test.ml create mode 100644 OCaml/diff-37/buggy/testcases create mode 100644 OCaml/diff-37/metadata.json create mode 100644 OCaml/diff-38/.dockerignore create mode 100644 OCaml/diff-38/Dockerfile create mode 100644 OCaml/diff-38/buggy/src.ml create mode 100644 OCaml/diff-38/buggy/test.ml create mode 100644 OCaml/diff-38/buggy/testcases create mode 100644 OCaml/diff-38/metadata.json create mode 100644 OCaml/diff-39/.dockerignore create mode 100644 OCaml/diff-39/Dockerfile create mode 100644 OCaml/diff-39/buggy/src.ml create mode 100644 OCaml/diff-39/buggy/test.ml create mode 100644 OCaml/diff-39/buggy/testcases create mode 100644 OCaml/diff-39/metadata.json create mode 100644 OCaml/diff-4/.dockerignore create mode 100644 OCaml/diff-4/Dockerfile create mode 100644 OCaml/diff-4/buggy/src.ml create mode 100644 OCaml/diff-4/buggy/test.ml create mode 100644 OCaml/diff-4/buggy/testcases create mode 100644 OCaml/diff-4/metadata.json create mode 100644 OCaml/diff-40/.dockerignore create mode 100644 OCaml/diff-40/Dockerfile create mode 100644 OCaml/diff-40/buggy/src.ml create mode 100644 OCaml/diff-40/buggy/test.ml create mode 100644 OCaml/diff-40/buggy/testcases create mode 100644 OCaml/diff-40/metadata.json create mode 100644 OCaml/diff-41/.dockerignore create mode 100644 OCaml/diff-41/Dockerfile create mode 100644 OCaml/diff-41/buggy/src.ml create mode 100644 OCaml/diff-41/buggy/test.ml create mode 100644 OCaml/diff-41/buggy/testcases create mode 100644 OCaml/diff-41/metadata.json create mode 100644 OCaml/diff-42/.dockerignore create mode 100644 OCaml/diff-42/Dockerfile create mode 100644 OCaml/diff-42/buggy/src.ml create mode 100644 OCaml/diff-42/buggy/test.ml create mode 100644 OCaml/diff-42/buggy/testcases create mode 100644 OCaml/diff-42/metadata.json create mode 100644 OCaml/diff-43/.dockerignore create mode 100644 OCaml/diff-43/Dockerfile create mode 100644 OCaml/diff-43/buggy/src.ml create mode 100644 OCaml/diff-43/buggy/test.ml create mode 100644 OCaml/diff-43/buggy/testcases create mode 100644 OCaml/diff-43/metadata.json create mode 100644 OCaml/diff-44/.dockerignore create mode 100644 OCaml/diff-44/Dockerfile create mode 100644 OCaml/diff-44/buggy/src.ml create mode 100644 OCaml/diff-44/buggy/test.ml create mode 100644 OCaml/diff-44/buggy/testcases create mode 100644 OCaml/diff-44/metadata.json create mode 100644 OCaml/diff-45/.dockerignore create mode 100644 OCaml/diff-45/Dockerfile create mode 100644 OCaml/diff-45/buggy/src.ml create mode 100644 OCaml/diff-45/buggy/test.ml create mode 100644 OCaml/diff-45/buggy/testcases create mode 100644 OCaml/diff-45/metadata.json create mode 100644 OCaml/diff-46/.dockerignore create mode 100644 OCaml/diff-46/Dockerfile create mode 100644 OCaml/diff-46/buggy/src.ml create mode 100644 OCaml/diff-46/buggy/test.ml create mode 100644 OCaml/diff-46/buggy/testcases create mode 100644 OCaml/diff-46/metadata.json create mode 100644 OCaml/diff-47/.dockerignore create mode 100644 OCaml/diff-47/Dockerfile create mode 100644 OCaml/diff-47/buggy/src.ml create mode 100644 OCaml/diff-47/buggy/test.ml create mode 100644 OCaml/diff-47/buggy/testcases create mode 100644 OCaml/diff-47/metadata.json create mode 100644 OCaml/diff-48/.dockerignore create mode 100644 OCaml/diff-48/Dockerfile create mode 100644 OCaml/diff-48/buggy/src.ml create mode 100644 OCaml/diff-48/buggy/test.ml create mode 100644 OCaml/diff-48/buggy/testcases create mode 100644 OCaml/diff-48/metadata.json create mode 100644 OCaml/diff-49/.dockerignore create mode 100644 OCaml/diff-49/Dockerfile create mode 100644 OCaml/diff-49/buggy/src.ml create mode 100644 OCaml/diff-49/buggy/test.ml create mode 100644 OCaml/diff-49/buggy/testcases create mode 100644 OCaml/diff-49/metadata.json create mode 100644 OCaml/diff-5/.dockerignore create mode 100644 OCaml/diff-5/Dockerfile create mode 100644 OCaml/diff-5/buggy/src.ml create mode 100644 OCaml/diff-5/buggy/test.ml create mode 100644 OCaml/diff-5/buggy/testcases create mode 100644 OCaml/diff-5/metadata.json create mode 100644 OCaml/diff-50/.dockerignore create mode 100644 OCaml/diff-50/Dockerfile create mode 100644 OCaml/diff-50/buggy/src.ml create mode 100644 OCaml/diff-50/buggy/test.ml create mode 100644 OCaml/diff-50/buggy/testcases create mode 100644 OCaml/diff-50/metadata.json create mode 100644 OCaml/diff-51/.dockerignore create mode 100644 OCaml/diff-51/Dockerfile create mode 100644 OCaml/diff-51/buggy/src.ml create mode 100644 OCaml/diff-51/buggy/test.ml create mode 100644 OCaml/diff-51/buggy/testcases create mode 100644 OCaml/diff-51/metadata.json create mode 100644 OCaml/diff-52/.dockerignore create mode 100644 OCaml/diff-52/Dockerfile create mode 100644 OCaml/diff-52/buggy/src.ml create mode 100644 OCaml/diff-52/buggy/test.ml create mode 100644 OCaml/diff-52/buggy/testcases create mode 100644 OCaml/diff-52/metadata.json create mode 100644 OCaml/diff-53/.dockerignore create mode 100644 OCaml/diff-53/Dockerfile create mode 100644 OCaml/diff-53/buggy/src.ml create mode 100644 OCaml/diff-53/buggy/test.ml create mode 100644 OCaml/diff-53/buggy/testcases create mode 100644 OCaml/diff-53/metadata.json create mode 100644 OCaml/diff-54/.dockerignore create mode 100644 OCaml/diff-54/Dockerfile create mode 100644 OCaml/diff-54/buggy/src.ml create mode 100644 OCaml/diff-54/buggy/test.ml create mode 100644 OCaml/diff-54/buggy/testcases create mode 100644 OCaml/diff-54/metadata.json create mode 100644 OCaml/diff-55/.dockerignore create mode 100644 OCaml/diff-55/Dockerfile create mode 100644 OCaml/diff-55/buggy/src.ml create mode 100644 OCaml/diff-55/buggy/test.ml create mode 100644 OCaml/diff-55/buggy/testcases create mode 100644 OCaml/diff-55/metadata.json create mode 100644 OCaml/diff-56/.dockerignore create mode 100644 OCaml/diff-56/Dockerfile create mode 100644 OCaml/diff-56/buggy/src.ml create mode 100644 OCaml/diff-56/buggy/test.ml create mode 100644 OCaml/diff-56/buggy/testcases create mode 100644 OCaml/diff-56/metadata.json create mode 100644 OCaml/diff-57/.dockerignore create mode 100644 OCaml/diff-57/Dockerfile create mode 100644 OCaml/diff-57/buggy/src.ml create mode 100644 OCaml/diff-57/buggy/test.ml create mode 100644 OCaml/diff-57/buggy/testcases create mode 100644 OCaml/diff-57/metadata.json create mode 100644 OCaml/diff-58/.dockerignore create mode 100644 OCaml/diff-58/Dockerfile create mode 100644 OCaml/diff-58/buggy/src.ml create mode 100644 OCaml/diff-58/buggy/test.ml create mode 100644 OCaml/diff-58/buggy/testcases create mode 100644 OCaml/diff-58/metadata.json create mode 100644 OCaml/diff-59/.dockerignore create mode 100644 OCaml/diff-59/Dockerfile create mode 100644 OCaml/diff-59/buggy/src.ml create mode 100644 OCaml/diff-59/buggy/test.ml create mode 100644 OCaml/diff-59/buggy/testcases create mode 100644 OCaml/diff-59/metadata.json create mode 100644 OCaml/diff-6/.dockerignore create mode 100644 OCaml/diff-6/Dockerfile create mode 100644 OCaml/diff-6/buggy/src.ml create mode 100644 OCaml/diff-6/buggy/test.ml create mode 100644 OCaml/diff-6/buggy/testcases create mode 100644 OCaml/diff-6/metadata.json create mode 100644 OCaml/diff-60/.dockerignore create mode 100644 OCaml/diff-60/Dockerfile create mode 100644 OCaml/diff-60/buggy/src.ml create mode 100644 OCaml/diff-60/buggy/test.ml create mode 100644 OCaml/diff-60/buggy/testcases create mode 100644 OCaml/diff-60/metadata.json create mode 100644 OCaml/diff-61/.dockerignore create mode 100644 OCaml/diff-61/Dockerfile create mode 100644 OCaml/diff-61/buggy/src.ml create mode 100644 OCaml/diff-61/buggy/test.ml create mode 100644 OCaml/diff-61/buggy/testcases create mode 100644 OCaml/diff-61/metadata.json create mode 100644 OCaml/diff-62/.dockerignore create mode 100644 OCaml/diff-62/Dockerfile create mode 100644 OCaml/diff-62/buggy/src.ml create mode 100644 OCaml/diff-62/buggy/test.ml create mode 100644 OCaml/diff-62/buggy/testcases create mode 100644 OCaml/diff-62/metadata.json create mode 100644 OCaml/diff-63/.dockerignore create mode 100644 OCaml/diff-63/Dockerfile create mode 100644 OCaml/diff-63/buggy/src.ml create mode 100644 OCaml/diff-63/buggy/test.ml create mode 100644 OCaml/diff-63/buggy/testcases create mode 100644 OCaml/diff-63/metadata.json create mode 100644 OCaml/diff-64/.dockerignore create mode 100644 OCaml/diff-64/Dockerfile create mode 100644 OCaml/diff-64/buggy/src.ml create mode 100644 OCaml/diff-64/buggy/test.ml create mode 100644 OCaml/diff-64/buggy/testcases create mode 100644 OCaml/diff-64/metadata.json create mode 100644 OCaml/diff-65/.dockerignore create mode 100644 OCaml/diff-65/Dockerfile create mode 100644 OCaml/diff-65/buggy/src.ml create mode 100644 OCaml/diff-65/buggy/test.ml create mode 100644 OCaml/diff-65/buggy/testcases create mode 100644 OCaml/diff-65/metadata.json create mode 100644 OCaml/diff-66/.dockerignore create mode 100644 OCaml/diff-66/Dockerfile create mode 100644 OCaml/diff-66/buggy/src.ml create mode 100644 OCaml/diff-66/buggy/test.ml create mode 100644 OCaml/diff-66/buggy/testcases create mode 100644 OCaml/diff-66/metadata.json create mode 100644 OCaml/diff-67/.dockerignore create mode 100644 OCaml/diff-67/Dockerfile create mode 100644 OCaml/diff-67/buggy/src.ml create mode 100644 OCaml/diff-67/buggy/test.ml create mode 100644 OCaml/diff-67/buggy/testcases create mode 100644 OCaml/diff-67/metadata.json create mode 100644 OCaml/diff-68/.dockerignore create mode 100644 OCaml/diff-68/Dockerfile create mode 100644 OCaml/diff-68/buggy/src.ml create mode 100644 OCaml/diff-68/buggy/test.ml create mode 100644 OCaml/diff-68/buggy/testcases create mode 100644 OCaml/diff-68/metadata.json create mode 100644 OCaml/diff-69/.dockerignore create mode 100644 OCaml/diff-69/Dockerfile create mode 100644 OCaml/diff-69/buggy/src.ml create mode 100644 OCaml/diff-69/buggy/test.ml create mode 100644 OCaml/diff-69/buggy/testcases create mode 100644 OCaml/diff-69/metadata.json create mode 100644 OCaml/diff-7/.dockerignore create mode 100644 OCaml/diff-7/Dockerfile create mode 100644 OCaml/diff-7/buggy/src.ml create mode 100644 OCaml/diff-7/buggy/test.ml create mode 100644 OCaml/diff-7/buggy/testcases create mode 100644 OCaml/diff-7/metadata.json create mode 100644 OCaml/diff-70/.dockerignore create mode 100644 OCaml/diff-70/Dockerfile create mode 100644 OCaml/diff-70/buggy/src.ml create mode 100644 OCaml/diff-70/buggy/test.ml create mode 100644 OCaml/diff-70/buggy/testcases create mode 100644 OCaml/diff-70/metadata.json create mode 100644 OCaml/diff-71/.dockerignore create mode 100644 OCaml/diff-71/Dockerfile create mode 100644 OCaml/diff-71/buggy/src.ml create mode 100644 OCaml/diff-71/buggy/test.ml create mode 100644 OCaml/diff-71/buggy/testcases create mode 100644 OCaml/diff-71/metadata.json create mode 100644 OCaml/diff-72/.dockerignore create mode 100644 OCaml/diff-72/Dockerfile create mode 100644 OCaml/diff-72/buggy/src.ml create mode 100644 OCaml/diff-72/buggy/test.ml create mode 100644 OCaml/diff-72/buggy/testcases create mode 100644 OCaml/diff-72/metadata.json create mode 100644 OCaml/diff-73/.dockerignore create mode 100644 OCaml/diff-73/Dockerfile create mode 100644 OCaml/diff-73/buggy/src.ml create mode 100644 OCaml/diff-73/buggy/test.ml create mode 100644 OCaml/diff-73/buggy/testcases create mode 100644 OCaml/diff-73/metadata.json create mode 100644 OCaml/diff-74/.dockerignore create mode 100644 OCaml/diff-74/Dockerfile create mode 100644 OCaml/diff-74/buggy/src.ml create mode 100644 OCaml/diff-74/buggy/test.ml create mode 100644 OCaml/diff-74/buggy/testcases create mode 100644 OCaml/diff-74/metadata.json create mode 100644 OCaml/diff-75/.dockerignore create mode 100644 OCaml/diff-75/Dockerfile create mode 100644 OCaml/diff-75/buggy/src.ml create mode 100644 OCaml/diff-75/buggy/test.ml create mode 100644 OCaml/diff-75/buggy/testcases create mode 100644 OCaml/diff-75/metadata.json create mode 100644 OCaml/diff-76/.dockerignore create mode 100644 OCaml/diff-76/Dockerfile create mode 100644 OCaml/diff-76/buggy/src.ml create mode 100644 OCaml/diff-76/buggy/test.ml create mode 100644 OCaml/diff-76/buggy/testcases create mode 100644 OCaml/diff-76/metadata.json create mode 100644 OCaml/diff-77/.dockerignore create mode 100644 OCaml/diff-77/Dockerfile create mode 100644 OCaml/diff-77/buggy/src.ml create mode 100644 OCaml/diff-77/buggy/test.ml create mode 100644 OCaml/diff-77/buggy/testcases create mode 100644 OCaml/diff-77/metadata.json create mode 100644 OCaml/diff-78/.dockerignore create mode 100644 OCaml/diff-78/Dockerfile create mode 100644 OCaml/diff-78/buggy/src.ml create mode 100644 OCaml/diff-78/buggy/test.ml create mode 100644 OCaml/diff-78/buggy/testcases create mode 100644 OCaml/diff-78/metadata.json create mode 100644 OCaml/diff-79/.dockerignore create mode 100644 OCaml/diff-79/Dockerfile create mode 100644 OCaml/diff-79/buggy/src.ml create mode 100644 OCaml/diff-79/buggy/test.ml create mode 100644 OCaml/diff-79/buggy/testcases create mode 100644 OCaml/diff-79/metadata.json create mode 100644 OCaml/diff-8/.dockerignore create mode 100644 OCaml/diff-8/Dockerfile create mode 100644 OCaml/diff-8/buggy/src.ml create mode 100644 OCaml/diff-8/buggy/test.ml create mode 100644 OCaml/diff-8/buggy/testcases create mode 100644 OCaml/diff-8/metadata.json create mode 100644 OCaml/diff-80/.dockerignore create mode 100644 OCaml/diff-80/Dockerfile create mode 100644 OCaml/diff-80/buggy/src.ml create mode 100644 OCaml/diff-80/buggy/test.ml create mode 100644 OCaml/diff-80/buggy/testcases create mode 100644 OCaml/diff-80/metadata.json create mode 100644 OCaml/diff-81/.dockerignore create mode 100644 OCaml/diff-81/Dockerfile create mode 100644 OCaml/diff-81/buggy/src.ml create mode 100644 OCaml/diff-81/buggy/test.ml create mode 100644 OCaml/diff-81/buggy/testcases create mode 100644 OCaml/diff-81/metadata.json create mode 100644 OCaml/diff-82/.dockerignore create mode 100644 OCaml/diff-82/Dockerfile create mode 100644 OCaml/diff-82/buggy/src.ml create mode 100644 OCaml/diff-82/buggy/test.ml create mode 100644 OCaml/diff-82/buggy/testcases create mode 100644 OCaml/diff-82/metadata.json create mode 100644 OCaml/diff-83/.dockerignore create mode 100644 OCaml/diff-83/Dockerfile create mode 100644 OCaml/diff-83/buggy/src.ml create mode 100644 OCaml/diff-83/buggy/test.ml create mode 100644 OCaml/diff-83/buggy/testcases create mode 100644 OCaml/diff-83/metadata.json create mode 100644 OCaml/diff-84/.dockerignore create mode 100644 OCaml/diff-84/Dockerfile create mode 100644 OCaml/diff-84/buggy/src.ml create mode 100644 OCaml/diff-84/buggy/test.ml create mode 100644 OCaml/diff-84/buggy/testcases create mode 100644 OCaml/diff-84/metadata.json create mode 100644 OCaml/diff-85/.dockerignore create mode 100644 OCaml/diff-85/Dockerfile create mode 100644 OCaml/diff-85/buggy/src.ml create mode 100644 OCaml/diff-85/buggy/test.ml create mode 100644 OCaml/diff-85/buggy/testcases create mode 100644 OCaml/diff-85/metadata.json create mode 100644 OCaml/diff-86/.dockerignore create mode 100644 OCaml/diff-86/Dockerfile create mode 100644 OCaml/diff-86/buggy/src.ml create mode 100644 OCaml/diff-86/buggy/test.ml create mode 100644 OCaml/diff-86/buggy/testcases create mode 100644 OCaml/diff-86/metadata.json create mode 100644 OCaml/diff-87/.dockerignore create mode 100644 OCaml/diff-87/Dockerfile create mode 100644 OCaml/diff-87/buggy/src.ml create mode 100644 OCaml/diff-87/buggy/test.ml create mode 100644 OCaml/diff-87/buggy/testcases create mode 100644 OCaml/diff-87/metadata.json create mode 100644 OCaml/diff-88/.dockerignore create mode 100644 OCaml/diff-88/Dockerfile create mode 100644 OCaml/diff-88/buggy/src.ml create mode 100644 OCaml/diff-88/buggy/test.ml create mode 100644 OCaml/diff-88/buggy/testcases create mode 100644 OCaml/diff-88/metadata.json create mode 100644 OCaml/diff-89/.dockerignore create mode 100644 OCaml/diff-89/Dockerfile create mode 100644 OCaml/diff-89/buggy/src.ml create mode 100644 OCaml/diff-89/buggy/test.ml create mode 100644 OCaml/diff-89/buggy/testcases create mode 100644 OCaml/diff-89/metadata.json create mode 100644 OCaml/diff-9/.dockerignore create mode 100644 OCaml/diff-9/Dockerfile create mode 100644 OCaml/diff-9/buggy/src.ml create mode 100644 OCaml/diff-9/buggy/test.ml create mode 100644 OCaml/diff-9/buggy/testcases create mode 100644 OCaml/diff-9/metadata.json create mode 100644 OCaml/diff-90/.dockerignore create mode 100644 OCaml/diff-90/Dockerfile create mode 100644 OCaml/diff-90/buggy/src.ml create mode 100644 OCaml/diff-90/buggy/test.ml create mode 100644 OCaml/diff-90/buggy/testcases create mode 100644 OCaml/diff-90/metadata.json create mode 100644 OCaml/diff-91/.dockerignore create mode 100644 OCaml/diff-91/Dockerfile create mode 100644 OCaml/diff-91/buggy/src.ml create mode 100644 OCaml/diff-91/buggy/test.ml create mode 100644 OCaml/diff-91/buggy/testcases create mode 100644 OCaml/diff-91/metadata.json create mode 100644 OCaml/diff-92/.dockerignore create mode 100644 OCaml/diff-92/Dockerfile create mode 100644 OCaml/diff-92/buggy/src.ml create mode 100644 OCaml/diff-92/buggy/test.ml create mode 100644 OCaml/diff-92/buggy/testcases create mode 100644 OCaml/diff-92/metadata.json create mode 100644 OCaml/diff-93/.dockerignore create mode 100644 OCaml/diff-93/Dockerfile create mode 100644 OCaml/diff-93/buggy/src.ml create mode 100644 OCaml/diff-93/buggy/test.ml create mode 100644 OCaml/diff-93/buggy/testcases create mode 100644 OCaml/diff-93/metadata.json create mode 100644 OCaml/diff-94/.dockerignore create mode 100644 OCaml/diff-94/Dockerfile create mode 100644 OCaml/diff-94/buggy/src.ml create mode 100644 OCaml/diff-94/buggy/test.ml create mode 100644 OCaml/diff-94/buggy/testcases create mode 100644 OCaml/diff-94/metadata.json create mode 100644 OCaml/diff-95/.dockerignore create mode 100644 OCaml/diff-95/Dockerfile create mode 100644 OCaml/diff-95/buggy/src.ml create mode 100644 OCaml/diff-95/buggy/test.ml create mode 100644 OCaml/diff-95/buggy/testcases create mode 100644 OCaml/diff-95/metadata.json create mode 100644 OCaml/diff-96/.dockerignore create mode 100644 OCaml/diff-96/Dockerfile create mode 100644 OCaml/diff-96/buggy/src.ml create mode 100644 OCaml/diff-96/buggy/test.ml create mode 100644 OCaml/diff-96/buggy/testcases create mode 100644 OCaml/diff-96/metadata.json create mode 100644 OCaml/diff-97/.dockerignore create mode 100644 OCaml/diff-97/Dockerfile create mode 100644 OCaml/diff-97/buggy/src.ml create mode 100644 OCaml/diff-97/buggy/test.ml create mode 100644 OCaml/diff-97/buggy/testcases create mode 100644 OCaml/diff-97/metadata.json create mode 100644 OCaml/diff-98/.dockerignore create mode 100644 OCaml/diff-98/Dockerfile create mode 100644 OCaml/diff-98/buggy/src.ml create mode 100644 OCaml/diff-98/buggy/test.ml create mode 100644 OCaml/diff-98/buggy/testcases create mode 100644 OCaml/diff-98/metadata.json create mode 100644 OCaml/diff-99/.dockerignore create mode 100644 OCaml/diff-99/Dockerfile create mode 100644 OCaml/diff-99/buggy/src.ml create mode 100644 OCaml/diff-99/buggy/test.ml create mode 100644 OCaml/diff-99/buggy/testcases create mode 100644 OCaml/diff-99/metadata.json diff --git a/OCaml/diff-1/.dockerignore b/OCaml/diff-1/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-1/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-1/Dockerfile b/OCaml/diff-1/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-1/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-1/buggy/src.ml b/OCaml/diff-1/buggy/src.ml new file mode 100644 index 000000000..1456ca305 --- /dev/null +++ b/OCaml/diff-1/buggy/src.ml @@ -0,0 +1,24 @@ +exception EMPTYLIST + +type aexp = + | Const of int + | Var of string + | Sum of aexp list + | Times of aexp list + | Power of (string * int) + +let rec diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var b -> if str = b then Const 1 else Const 0 + | Power (pstr, i) -> + if str = pstr then Times [ Const i; Power (pstr, i - 1) ] else Const 0 + | Times alst -> ( + match alst with + | [] -> Const 0 + | [ h ] -> diff (h, str) + | h :: t -> + Sum [ Times (diff (h, str) :: t); Times [ h; diff (Times t, str) ] ] ) + | Sum [] -> Const 0 + | Sum (h :: []) -> Const 0 + | Sum (h :: t) -> Sum [ diff (h, str); diff (Sum t, str) ] diff --git a/OCaml/diff-1/buggy/test.ml b/OCaml/diff-1/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-1/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-1/buggy/testcases b/OCaml/diff-1/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-1/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-1/metadata.json b/OCaml/diff-1/metadata.json new file mode 100644 index 000000000..785002134 --- /dev/null +++ b/OCaml/diff-1/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-1", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-10/.dockerignore b/OCaml/diff-10/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-10/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-10/Dockerfile b/OCaml/diff-10/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-10/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-10/buggy/src.ml b/OCaml/diff-10/buggy/src.ml new file mode 100644 index 000000000..06a69e9df --- /dev/null +++ b/OCaml/diff-10/buggy/src.ml @@ -0,0 +1,32 @@ +exception Error of string + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + let rec diff_times (orihd : aexp) (li : aexp list) (s : string) (n : int) : + aexp = + match li with + | hd :: tl -> + if hd = orihd && n = 1 then Const 0 + else + Sum + (List.append + [ Times (diff (hd, s) :: tl) ] + [ diff_times orihd (List.append tl [ hd ]) s 1 ]) + in + + match aexp with + | Const _ -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, i) -> + if s = str then Times [ Const i; Power (s, i - 1) ] else Const 0 + | Times l -> + if l = [] then raise (Error "no times!") else diff_times (List.hd l) l str 0 + | Sum (hd :: tl) -> + if tl = [] then diff (hd, str) + else Sum (List.append [ diff (hd, str) ] [ diff (Sum tl, str) ]) diff --git a/OCaml/diff-10/buggy/test.ml b/OCaml/diff-10/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-10/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-10/buggy/testcases b/OCaml/diff-10/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-10/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-10/metadata.json b/OCaml/diff-10/metadata.json new file mode 100644 index 000000000..0f2cbb9e9 --- /dev/null +++ b/OCaml/diff-10/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-10", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-100/.dockerignore b/OCaml/diff-100/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-100/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-100/Dockerfile b/OCaml/diff-100/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-100/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-100/buggy/src.ml b/OCaml/diff-100/buggy/src.ml new file mode 100644 index 000000000..60566554a --- /dev/null +++ b/OCaml/diff-100/buggy/src.ml @@ -0,0 +1,37 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const n -> Const 0 + | Var k -> if k = var then Const 1 else Var k + | Power (s, n) -> + if s = var then + if n = 0 then Const 0 else Times [ Power (s, n - 1); Const n ] + else Const 0 + | Times li -> + let rec timesfun (exp : aexp list) (var : string) : aexp list = + match exp with + | [] -> [] + | hd :: tl -> ( + match hd with + | Const n -> [ Const n ] @ timesfun tl var + | Var k -> [ diff (hd, var) ] @ timesfun tl var + | Power (s, n) -> + if s = var then + if n = 0 then [ Const 0 ] @ timesfun tl var + else [ Times [ Power (s, n - 1); Const n ] ] @ timesfun tl var + else [ Const 1 ] @ timesfun tl var + | Times li -> [ diff (hd, var) ] @ timesfun tl var + | Sum li -> [ diff (hd, var) ] @ timesfun tl var ) + in + Times (timesfun li var) + | Sum li -> + let rec sumfun (exp : aexp list) : aexp list = + match exp with [] -> [] | hd :: tl -> [ diff (hd, var) ] @ sumfun tl + in + Sum (sumfun li) diff --git a/OCaml/diff-100/buggy/test.ml b/OCaml/diff-100/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-100/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-100/buggy/testcases b/OCaml/diff-100/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-100/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-100/metadata.json b/OCaml/diff-100/metadata.json new file mode 100644 index 000000000..0f9343814 --- /dev/null +++ b/OCaml/diff-100/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-100", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-11/.dockerignore b/OCaml/diff-11/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-11/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-11/Dockerfile b/OCaml/diff-11/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-11/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-11/buggy/src.ml b/OCaml/diff-11/buggy/src.ml new file mode 100644 index 000000000..06a69e9df --- /dev/null +++ b/OCaml/diff-11/buggy/src.ml @@ -0,0 +1,32 @@ +exception Error of string + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + let rec diff_times (orihd : aexp) (li : aexp list) (s : string) (n : int) : + aexp = + match li with + | hd :: tl -> + if hd = orihd && n = 1 then Const 0 + else + Sum + (List.append + [ Times (diff (hd, s) :: tl) ] + [ diff_times orihd (List.append tl [ hd ]) s 1 ]) + in + + match aexp with + | Const _ -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, i) -> + if s = str then Times [ Const i; Power (s, i - 1) ] else Const 0 + | Times l -> + if l = [] then raise (Error "no times!") else diff_times (List.hd l) l str 0 + | Sum (hd :: tl) -> + if tl = [] then diff (hd, str) + else Sum (List.append [ diff (hd, str) ] [ diff (Sum tl, str) ]) diff --git a/OCaml/diff-11/buggy/test.ml b/OCaml/diff-11/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-11/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-11/buggy/testcases b/OCaml/diff-11/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-11/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-11/metadata.json b/OCaml/diff-11/metadata.json new file mode 100644 index 000000000..861d9f70c --- /dev/null +++ b/OCaml/diff-11/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-11", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-12/.dockerignore b/OCaml/diff-12/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-12/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-12/Dockerfile b/OCaml/diff-12/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-12/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-12/buggy/src.ml b/OCaml/diff-12/buggy/src.ml new file mode 100644 index 000000000..3ece0be88 --- /dev/null +++ b/OCaml/diff-12/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((x : aexp), (y : string)) : aexp = + match x with + | Const c -> Const 0 + | Var a -> if a = y then Const 1 else Const 0 + | Power (a, b) -> + if a != y then Const 0 + else if b = 1 then Var a + else if b = 2 then Times [ Const 2; Var a ] + else Times [ Const b; Power (a, b - 1) ] + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, y); diff (Sum t, y) ] ) + | Times l -> ( + match l with + | [] -> Const 0 + | [ h ] -> diff (h, y) + | Const a :: t -> Times [ Const a; diff (Times t, y) ] + | h :: t -> + Sum [ Times [ diff (h, y); Times t ]; Times [ h; diff (Times t, y) ] ] + ) diff --git a/OCaml/diff-12/buggy/test.ml b/OCaml/diff-12/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-12/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-12/buggy/testcases b/OCaml/diff-12/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-12/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-12/metadata.json b/OCaml/diff-12/metadata.json new file mode 100644 index 000000000..6e33bca7d --- /dev/null +++ b/OCaml/diff-12/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-12", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-13/.dockerignore b/OCaml/diff-13/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-13/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-13/Dockerfile b/OCaml/diff-13/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-13/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-13/buggy/src.ml b/OCaml/diff-13/buggy/src.ml new file mode 100644 index 000000000..3ece0be88 --- /dev/null +++ b/OCaml/diff-13/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((x : aexp), (y : string)) : aexp = + match x with + | Const c -> Const 0 + | Var a -> if a = y then Const 1 else Const 0 + | Power (a, b) -> + if a != y then Const 0 + else if b = 1 then Var a + else if b = 2 then Times [ Const 2; Var a ] + else Times [ Const b; Power (a, b - 1) ] + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, y); diff (Sum t, y) ] ) + | Times l -> ( + match l with + | [] -> Const 0 + | [ h ] -> diff (h, y) + | Const a :: t -> Times [ Const a; diff (Times t, y) ] + | h :: t -> + Sum [ Times [ diff (h, y); Times t ]; Times [ h; diff (Times t, y) ] ] + ) diff --git a/OCaml/diff-13/buggy/test.ml b/OCaml/diff-13/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-13/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-13/buggy/testcases b/OCaml/diff-13/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-13/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-13/metadata.json b/OCaml/diff-13/metadata.json new file mode 100644 index 000000000..347705c08 --- /dev/null +++ b/OCaml/diff-13/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-13", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-14/.dockerignore b/OCaml/diff-14/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-14/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-14/Dockerfile b/OCaml/diff-14/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-14/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-14/buggy/src.ml b/OCaml/diff-14/buggy/src.ml new file mode 100644 index 000000000..3ece0be88 --- /dev/null +++ b/OCaml/diff-14/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((x : aexp), (y : string)) : aexp = + match x with + | Const c -> Const 0 + | Var a -> if a = y then Const 1 else Const 0 + | Power (a, b) -> + if a != y then Const 0 + else if b = 1 then Var a + else if b = 2 then Times [ Const 2; Var a ] + else Times [ Const b; Power (a, b - 1) ] + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, y); diff (Sum t, y) ] ) + | Times l -> ( + match l with + | [] -> Const 0 + | [ h ] -> diff (h, y) + | Const a :: t -> Times [ Const a; diff (Times t, y) ] + | h :: t -> + Sum [ Times [ diff (h, y); Times t ]; Times [ h; diff (Times t, y) ] ] + ) diff --git a/OCaml/diff-14/buggy/test.ml b/OCaml/diff-14/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-14/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-14/buggy/testcases b/OCaml/diff-14/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-14/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-14/metadata.json b/OCaml/diff-14/metadata.json new file mode 100644 index 000000000..c8ec17f3c --- /dev/null +++ b/OCaml/diff-14/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-14", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-15/.dockerignore b/OCaml/diff-15/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-15/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-15/Dockerfile b/OCaml/diff-15/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-15/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-15/buggy/src.ml b/OCaml/diff-15/buggy/src.ml new file mode 100644 index 000000000..813c3b780 --- /dev/null +++ b/OCaml/diff-15/buggy/src.ml @@ -0,0 +1,32 @@ +exception InvalidArgument + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let diff ((e : aexp), (str : string)) : aexp = + let rec diff_sub ((e : aexp), (str : string)) : aexp = + match e with + | Const n -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (str, n) -> Times [ Const n; Power (str, n - 1) ] + | Times lst -> ( + match lst with + | [] -> raise InvalidArgument + | [ a ] -> diff_sub (a, str) + | a :: t -> + Sum + [ + Times [ diff_sub (a, str); Times t ]; + Times [ a; diff_sub (Times t, str) ]; + ] ) + | Sum lst -> ( + match lst with + | [] -> raise InvalidArgument + | [ a ] -> diff_sub (a, str) + | a :: t -> Sum [ diff_sub (a, str); diff_sub (Sum t, str) ] ) + in + diff_sub (e, str) diff --git a/OCaml/diff-15/buggy/test.ml b/OCaml/diff-15/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-15/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-15/buggy/testcases b/OCaml/diff-15/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-15/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-15/metadata.json b/OCaml/diff-15/metadata.json new file mode 100644 index 000000000..9ff01936e --- /dev/null +++ b/OCaml/diff-15/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-15", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-16/.dockerignore b/OCaml/diff-16/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-16/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-16/Dockerfile b/OCaml/diff-16/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-16/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-16/buggy/src.ml b/OCaml/diff-16/buggy/src.ml new file mode 100644 index 000000000..0dbf07335 --- /dev/null +++ b/OCaml/diff-16/buggy/src.ml @@ -0,0 +1,43 @@ +exception InvalidArgument + +exception L2AL_null + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + let rec list2aexplist ((aexplist : aexp list), (st : string)) : aexp list = + match aexplist with + | [ h ] -> [ diff (h, st) ] + | h :: t -> [ diff (h, st) ] @ list2aexplist (t, st) + | [] -> raise L2AL_null + in + + match aexp with + | Const c -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, n) -> + if n = 0 then Const 1 + else if n = 1 && s = str then Const 2 + else if n = 1 && s != str then Const 3 + else if s = str then Times [ Const n; Power (s, n - 1) ] + else Const 0 + | Sum aexplist -> ( + match aexplist with + | [] -> raise InvalidArgument + | [ h ] -> diff (h, str) + | h :: t -> Sum ([ diff (h, str) ] @ list2aexplist (t, str)) ) + | Times aexplist -> ( + match aexplist with + | [] -> raise InvalidArgument + | [ h ] -> diff (h, str) + | h :: t -> + Sum + [ + Times ([ diff (h, str) ] @ t); + Times ([ h ] @ [ diff (Times t, str) ]); + ] ) diff --git a/OCaml/diff-16/buggy/test.ml b/OCaml/diff-16/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-16/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-16/buggy/testcases b/OCaml/diff-16/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-16/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-16/metadata.json b/OCaml/diff-16/metadata.json new file mode 100644 index 000000000..89d21a428 --- /dev/null +++ b/OCaml/diff-16/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-16", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-17/.dockerignore b/OCaml/diff-17/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-17/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-17/Dockerfile b/OCaml/diff-17/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-17/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-17/buggy/src.ml b/OCaml/diff-17/buggy/src.ml new file mode 100644 index 000000000..5a49648bd --- /dev/null +++ b/OCaml/diff-17/buggy/src.ml @@ -0,0 +1,43 @@ +exception InvalidArgument + +exception L2AL_null + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + let rec list2aexplist ((aexplist : aexp list), (st : string)) : aexp list = + match aexplist with + | [ h ] -> [ diff (h, st) ] + | h :: t -> [ diff (h, st) ] @ list2aexplist (t, st) + | [] -> raise L2AL_null + in + + match aexp with + | Const c -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, n) -> + if n = 0 then Const 1 + else if n = 1 && s = str then Const 1 + else if n = 1 && s != str then Const 0 + else if s = str then Times [ Const n; Power (s, n - 1) ] + else Const 0 + | Sum aexplist -> ( + match aexplist with + | [] -> raise InvalidArgument + | [ h ] -> diff (h, str) + | h :: t -> Sum ([ diff (h, str) ] @ list2aexplist (t, str)) ) + | Times aexplist -> ( + match aexplist with + | [] -> raise InvalidArgument + | [ h ] -> diff (h, str) + | h :: t -> + Sum + [ + Times ([ diff (h, str) ] @ t); + Times ([ h ] @ [ diff (Times t, str) ]); + ] ) diff --git a/OCaml/diff-17/buggy/test.ml b/OCaml/diff-17/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-17/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-17/buggy/testcases b/OCaml/diff-17/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-17/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-17/metadata.json b/OCaml/diff-17/metadata.json new file mode 100644 index 000000000..a5ce3d315 --- /dev/null +++ b/OCaml/diff-17/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-17", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-18/.dockerignore b/OCaml/diff-18/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-18/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-18/Dockerfile b/OCaml/diff-18/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-18/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-18/buggy/src.ml b/OCaml/diff-18/buggy/src.ml new file mode 100644 index 000000000..d7aa05af8 --- /dev/null +++ b/OCaml/diff-18/buggy/src.ml @@ -0,0 +1,30 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((e : aexp), (str : string)) : aexp = + match e with + | Const i -> Const 0 + | Var str1 -> if str1 = str then Const 1 else Const 0 + | Power (str1, i) -> + if i = 0 then Const 0 + else if str1 = str && i = 1 then Const 1 + else Times [ Const i; Power (str1, i - 1) ] + | Sum [] -> raise InvalidArgument + | Sum lst -> + if List.length lst = 1 then diff (List.hd lst, str) + else Sum [ diff (List.hd lst, str); diff (Sum (List.tl lst), str) ] + | Times [] -> raise InvalidArgument + | Times lst -> + if List.length lst = 1 then diff (List.hd lst, str) + else + Sum + [ + Times (diff (List.hd lst, str) :: List.tl lst); + Times [ List.hd lst; diff (Times (List.tl lst), str) ]; + ] diff --git a/OCaml/diff-18/buggy/test.ml b/OCaml/diff-18/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-18/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-18/buggy/testcases b/OCaml/diff-18/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-18/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-18/metadata.json b/OCaml/diff-18/metadata.json new file mode 100644 index 000000000..5e52d6485 --- /dev/null +++ b/OCaml/diff-18/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-18", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-19/.dockerignore b/OCaml/diff-19/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-19/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-19/Dockerfile b/OCaml/diff-19/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-19/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-19/buggy/src.ml b/OCaml/diff-19/buggy/src.ml new file mode 100644 index 000000000..75f673023 --- /dev/null +++ b/OCaml/diff-19/buggy/src.ml @@ -0,0 +1,34 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((a : aexp), (stri : string)) : aexp = + match a with + | Const na -> Const 0 + | Var strin -> if stri = strin then Const 1 else Const 0 + | Power (strin, na) -> + if not (strin = stri) then Const 0 + else if na = 0 then Const 0 + else if na = 1 then Const 1 + else if na = 2 then Times [ Const 2; Var strin ] + else Times [ Const na; Power (strin, na - 1) ] + | Times ((Const na) :: tl) -> + if na = 0 then Const 0 + else if na = 1 then diff (Times tl, stri) + else Times [ Const na; diff (Times tl, stri) ] + | Times (hd :: tl) -> + if tl = [] then diff (hd, stri) + else + Sum + [ Times (diff (hd, stri) :: tl); Times [ hd; diff (Times tl, stri) ] ] + | Times [] -> raise InvalidArgument + | Sum ((Const na) :: tl) -> diff (Sum tl, stri) + | Sum (hd :: tl) -> + if tl = [] then diff (hd, stri) + else Sum [ diff (hd, stri); diff (Sum tl, stri) ] + | Sum [] -> raise InvalidArgument diff --git a/OCaml/diff-19/buggy/test.ml b/OCaml/diff-19/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-19/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-19/buggy/testcases b/OCaml/diff-19/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-19/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-19/metadata.json b/OCaml/diff-19/metadata.json new file mode 100644 index 000000000..1af4661be --- /dev/null +++ b/OCaml/diff-19/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-19", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-2/.dockerignore b/OCaml/diff-2/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-2/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-2/Dockerfile b/OCaml/diff-2/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-2/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-2/buggy/src.ml b/OCaml/diff-2/buggy/src.ml new file mode 100644 index 000000000..5addb2f9c --- /dev/null +++ b/OCaml/diff-2/buggy/src.ml @@ -0,0 +1,20 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((a : aexp), (s : string)) : aexp = + match a with + | Const i -> Const 0 + | Var v -> if v = s then Const 1 else Const 0 + | Power (v, p) -> + if v = s then Times [ Const p; Power (v, p - 1) ] else Const 0 + | Times l -> + Sum + (List.map + (fun (x : aexp) -> + Times (diff (x, s) :: List.filter (fun (y : aexp) -> y != x) l)) + l) + | Sum l -> Sum (List.map (fun (x : aexp) -> diff (x, s)) l) diff --git a/OCaml/diff-2/buggy/test.ml b/OCaml/diff-2/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-2/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-2/buggy/testcases b/OCaml/diff-2/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-2/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-2/metadata.json b/OCaml/diff-2/metadata.json new file mode 100644 index 000000000..e3c6122ef --- /dev/null +++ b/OCaml/diff-2/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-2", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-20/.dockerignore b/OCaml/diff-20/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-20/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-20/Dockerfile b/OCaml/diff-20/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-20/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-20/buggy/src.ml b/OCaml/diff-20/buggy/src.ml new file mode 100644 index 000000000..ed98557b8 --- /dev/null +++ b/OCaml/diff-20/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((aexp : aexp), (s : string)) : aexp = + match (aexp, s) with + | Sum [], s -> raise InvalidArgument + | Times [], s -> raise InvalidArgument + | Const i, s -> Const 0 + | Var s1, s -> if s1 = s then Const 1 else Const 0 + | Power (s1, a), s -> + if s1 = s then Times [ Const a; Power (s1, a - 1) ] + else Times [ Const a; diff (Var s1, s); Power (s1, a - 1) ] + | Sum [ a; b ], s -> Sum [ diff (a, s); diff (b, s) ] + | Sum (a :: sl), s -> Sum [ diff (a, s); diff (Sum sl, s) ] + | Times [ a; b ], s -> + Sum [ Times [ diff (a, s); b ]; Times [ a; diff (b, s) ] ] + | Times (a :: sl), s -> + Sum [ Times (diff (a, s) :: sl); Times [ a; diff (Times sl, s) ] ] diff --git a/OCaml/diff-20/buggy/test.ml b/OCaml/diff-20/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-20/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-20/buggy/testcases b/OCaml/diff-20/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-20/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-20/metadata.json b/OCaml/diff-20/metadata.json new file mode 100644 index 000000000..8b60d2ade --- /dev/null +++ b/OCaml/diff-20/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-20", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-21/.dockerignore b/OCaml/diff-21/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-21/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-21/Dockerfile b/OCaml/diff-21/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-21/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-21/buggy/src.ml b/OCaml/diff-21/buggy/src.ml new file mode 100644 index 000000000..4b2e9d719 --- /dev/null +++ b/OCaml/diff-21/buggy/src.ml @@ -0,0 +1,81 @@ +exception InvalidArgument + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec r_diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var v -> if v = str then Const 1 else Const 0 + | Power (v, i) -> + if not (v = str) then Const 0 + else if i = 0 then Const 0 + else if i = 1 then Const 1 + else if i = 2 then Times [ Const i; Var v ] + else Times [ Const i; Power (v, i - 1) ] + | Times (hd :: tl) -> + if tl = [] then r_diff (hd, str) + else + Sum + [ + Times (r_diff (hd, str) :: tl); Times [ hd; r_diff (Times tl, str) ]; + ] + | Times [] -> raise InvalidArgument + | Sum (hd :: tl) -> + if tl = [] then r_diff (hd, str) + else Sum [ r_diff (hd, str); r_diff (Sum tl, str) ] + | Sum [] -> raise InvalidArgument + + +let rec contain_zero (lst : aexp list) : bool = + match lst with + | [] -> false + | hd :: tl -> if hd = Const 0 then true else contain_zero tl + + +let rec minimize_sum (lst : aexp list) : aexp list = + match lst with + | [] -> [] + | hd :: tl -> ( + match hd with + | Const 0 -> minimize_sum tl + | Sum lst -> lst @ minimize_sum tl + | _ -> hd :: minimize_sum tl ) + + +let rec minimize_times (lst : aexp list) : aexp list = + match lst with + | [] -> [] + | hd :: tl -> ( + match hd with + | Const 1 -> minimize_times tl + | Times lst -> lst @ minimize_times tl + | _ -> hd :: minimize_times tl ) + + +let rec minimize (aexp : aexp) : aexp = + match aexp with + | Const i -> Const i + | Var v -> Var v + | Power (v, i) -> Power (v, i) + | Sum lst -> + if lst = [] then Const 0 + else if List.length lst = 1 then List.hd lst + else Sum (List.map minimize (minimize_sum lst)) + | Times lst -> + if lst = [] then Const 0 + else if contain_zero lst then Const 0 + else if List.length lst = 1 then List.hd lst + else Times (List.map minimize (minimize_times lst)) + + +let rec r_minimize (aexp : aexp) : aexp = + if aexp = minimize aexp then aexp else r_minimize (minimize aexp) + + +let diff ((aexp : aexp), (str : string)) : aexp = + r_minimize (r_diff (aexp, str)) diff --git a/OCaml/diff-21/buggy/test.ml b/OCaml/diff-21/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-21/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-21/buggy/testcases b/OCaml/diff-21/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-21/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-21/metadata.json b/OCaml/diff-21/metadata.json new file mode 100644 index 000000000..38a0b6a3e --- /dev/null +++ b/OCaml/diff-21/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-21", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-22/.dockerignore b/OCaml/diff-22/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-22/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-22/Dockerfile b/OCaml/diff-22/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-22/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-22/buggy/src.ml b/OCaml/diff-22/buggy/src.ml new file mode 100644 index 000000000..0308fd6ae --- /dev/null +++ b/OCaml/diff-22/buggy/src.ml @@ -0,0 +1,79 @@ +exception InvalidArgument + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec r_diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var v -> if v = str then Const 1 else Const 0 + | Power (v, i) -> + if not (v = str) then Const 0 + else if i = 0 then Const 0 + else if i = 1 then Const 1 + else if i = 2 then Times [ Const i; Var v ] + else Times [ Const i; Power (v, i - 1) ] + | Times (hd :: tl) -> + if tl = [] then r_diff (hd, str) + else + Sum + [ + Times (r_diff (hd, str) :: tl); Times [ hd; r_diff (Times tl, str) ]; + ] + | Times [] -> raise InvalidArgument + | Sum (hd :: tl) -> + if tl = [] then r_diff (hd, str) + else Sum [ r_diff (hd, str); r_diff (Sum tl, str) ] + | Sum [] -> raise InvalidArgument + + +let rec contain_zero (lst : aexp list) : bool = + match lst with + | [] -> false + | hd :: tl -> if hd = Const 0 then true else contain_zero tl + + +let rec minimize_sum (lst : aexp list) : aexp list = + match lst with + | [] -> [] + | hd :: tl -> ( + match hd with + | Const 0 -> minimize_sum tl + | Sum lst -> lst @ minimize_sum tl + | _ -> hd :: minimize_sum tl ) + + +let rec minimize_times (lst : aexp list) : aexp list = + match lst with + | [] -> [] + | Const 1 :: tl -> minimize_times tl + | Times lst :: tl -> lst @ minimize_times tl + | hd :: tl -> hd :: minimize_times tl + + +let rec minimize (aexp : aexp) : aexp = + match aexp with + | Const i -> Const i + | Var v -> Var v + | Power (v, i) -> Power (v, i) + | Sum lst -> + if lst = [] then Const 0 + else if List.length lst = 1 then List.hd lst + else Sum (List.map minimize (minimize_sum lst)) + | Times lst -> + if lst = [] then Const 0 + else if contain_zero lst then Const 0 + else if List.length lst = 1 then List.hd lst + else Times (List.map minimize (minimize_times lst)) + + +let rec r_minimize (aexp : aexp) : aexp = + if aexp = minimize aexp then aexp else r_minimize (minimize aexp) + + +let diff ((aexp : aexp), (str : string)) : aexp = + r_minimize (r_diff (aexp, str)) diff --git a/OCaml/diff-22/buggy/test.ml b/OCaml/diff-22/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-22/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-22/buggy/testcases b/OCaml/diff-22/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-22/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-22/metadata.json b/OCaml/diff-22/metadata.json new file mode 100644 index 000000000..1769d175e --- /dev/null +++ b/OCaml/diff-22/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-22", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-23/.dockerignore b/OCaml/diff-23/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-23/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-23/Dockerfile b/OCaml/diff-23/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-23/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-23/buggy/src.ml b/OCaml/diff-23/buggy/src.ml new file mode 100644 index 000000000..ae3d9c184 --- /dev/null +++ b/OCaml/diff-23/buggy/src.ml @@ -0,0 +1,50 @@ +type aexp = + | Const of int + | Var of string + | Power of string * int + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec simplify a = + match a with + | Power (str, n) -> if n = 0 then Const 1 else if n = 1 then Var str else a + | Times (hd :: tl) -> + if tl = [] then simplify hd + else if simplify hd = Const 0 || simplify (Times tl) = Const 0 then + Const 0 + else if simplify hd = Const 1 then simplify (Times tl) + else if simplify (Times tl) = Const 1 then simplify hd + else Times ([ simplify hd ] @ [ simplify (Times tl) ]) + | Sum (hd :: tl) -> + if tl = [] then simplify hd + else if simplify hd = Const 0 then simplify (Sum tl) + else if simplify (Sum tl) = Const 0 then simplify hd + else Sum ([ simplify hd ] @ [ simplify (Times tl) ]) + | _ -> a + + +let rec diff (a, s) = + match a with + | Const _ -> Const 0 + | Var str -> if s = str then Const 1 else Const 0 + | Power (str, n) -> + if s = str then simplify (Times ([ Const n ] @ [ Power (str, n - 1) ])) + else Const 0 + | Times (hd :: tl) -> + simplify + (Sum + ( [ Times ([ diff (hd, s) ] @ tl) ] + @ [ + Times + ( [ hd ] + @ if tl = [] then [ Const 0 ] else [ diff (Times tl, s) ] ); + ] )) + | Times [] -> raise InvalidArgument + | Sum (hd :: tl) -> + simplify + (Sum + ( [ diff (hd, s) ] + @ if tl = [] then [ Const 0 ] else [ diff (Sum tl, s) ] )) + | Sum [] -> raise InvalidArgument diff --git a/OCaml/diff-23/buggy/test.ml b/OCaml/diff-23/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-23/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-23/buggy/testcases b/OCaml/diff-23/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-23/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-23/metadata.json b/OCaml/diff-23/metadata.json new file mode 100644 index 000000000..46c3dc6f6 --- /dev/null +++ b/OCaml/diff-23/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-23", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-24/.dockerignore b/OCaml/diff-24/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-24/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-24/Dockerfile b/OCaml/diff-24/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-24/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-24/buggy/src.ml b/OCaml/diff-24/buggy/src.ml new file mode 100644 index 000000000..d1a225132 --- /dev/null +++ b/OCaml/diff-24/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, n) -> + if s = str then Times [ Const n; Power (s, n - 1) ] else Const 0 + | Sum [] -> raise InvalidArgument + | Times [] -> raise InvalidArgument + | Sum el -> Sum (List.map (fun (x : aexp) -> diff (x, str)) el) + | Times el -> + Sum + (List.map + (fun (x : aexp) -> + Times (diff (x, str) :: List.filter (fun (y : aexp) -> x != y) el)) + el) diff --git a/OCaml/diff-24/buggy/test.ml b/OCaml/diff-24/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-24/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-24/buggy/testcases b/OCaml/diff-24/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-24/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-24/metadata.json b/OCaml/diff-24/metadata.json new file mode 100644 index 000000000..f4d1c9b67 --- /dev/null +++ b/OCaml/diff-24/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-24", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-25/.dockerignore b/OCaml/diff-25/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-25/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-25/Dockerfile b/OCaml/diff-25/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-25/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-25/buggy/src.ml b/OCaml/diff-25/buggy/src.ml new file mode 100644 index 000000000..0b6b5c45e --- /dev/null +++ b/OCaml/diff-25/buggy/src.ml @@ -0,0 +1,59 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((aexp : aexp), (instr : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var x -> if x = instr then Const 1 else Const 0 + | Power (x, y) -> + if x = instr && y = 0 then Const 0 + else if x = instr && y != 0 then Times [ Const y; Power (x, y - 1) ] + else Const 0 + | Times [] -> raise InvalidArgument + | Times lst -> timeProcess (lst, instr) + | Sum [] -> raise InvalidArgument + | Sum lst -> Sum (List.map (fun (x : aexp) -> diff (x, instr)) lst) + + +and timeProcess ((l : aexp list), (istr : string)) : aexp = + let check (x : aexp) : bool = + match x with + | Var x -> if x = istr then true else false + | Power (x, _) -> if x = istr then true else false + | _ -> false + in + + let varList : aexp list = List.filter (fun (x : aexp) -> check x) l in + if List.exists (fun (x : aexp) -> check x) l then + Times + ( diff (polyProcess (varList, istr), istr) + :: List.filter (fun (x : aexp) -> not (check x)) l ) + else Const 0 + + +and polyProcess ((l : aexp list), (is : string)) : aexp = + let varToPower (__fun__ : aexp) : aexp = + match __fun__ with + | Var x -> Power (x, 1) + | Power (x, y) -> Power (x, y) + | _ -> raise InvalidArgument + in + + let powerFold (x : int) (__fun__ : aexp) : int = + match __fun__ with Power (_, a) -> x + a | _ -> raise InvalidArgument + in + + let poweredList : aexp list = List.map (fun (x : aexp) -> varToPower x) l in + + let rec fold_left (f : int -> aexp -> int) (a : int) (l : aexp list) : int = + match l with [] -> a | h :: t -> fold_left f (f a h) t + in + + let muled : int = fold_left powerFold 0 poweredList in + Power (is, muled) diff --git a/OCaml/diff-25/buggy/test.ml b/OCaml/diff-25/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-25/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-25/buggy/testcases b/OCaml/diff-25/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-25/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-25/metadata.json b/OCaml/diff-25/metadata.json new file mode 100644 index 000000000..22776269b --- /dev/null +++ b/OCaml/diff-25/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-25", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-26/.dockerignore b/OCaml/diff-26/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-26/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-26/Dockerfile b/OCaml/diff-26/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-26/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-26/buggy/src.ml b/OCaml/diff-26/buggy/src.ml new file mode 100644 index 000000000..24714f10e --- /dev/null +++ b/OCaml/diff-26/buggy/src.ml @@ -0,0 +1,56 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec cal ((form : aexp), (var : string)) : aexp = + match form with + | Const n -> Const 0 + | Var x -> if x = var then Const 1 else Const 0 + | Power (x, n) -> + if x = var then + if n = 0 then Const 0 + else if n = 1 then Const 1 + else Times [ Const n; Power (x, n - 1) ] + else Const 0 + | Times lst -> ( + if List.mem (Const 0) lst then Const 0 + else + match lst with + | [] -> raise InvalidArgument + | [ l ] -> cal (l, var) + | l :: r -> ( + match l with + | Const 1 -> cal (Times r, var) + | Const n -> Times [ l; cal (Times r, var) ] + | Var x -> + if x = var then Times (cal (l, var) :: r) + else Times [ l; cal (Times r, var) ] + | _ -> Times (cal (l, var) :: r) ) ) + | Sum lst -> ( + match lst with + | [] -> raise InvalidArgument + | [ l ] -> cal (l, var) + | l :: r -> Sum [ cal (l, var); cal (Sum r, var) ] ) + + +let notone (x : aexp) : bool = if x = Const 1 then false else true + +let notzero (x : aexp) : bool = if x = Const 0 then false else true + +let rec arrange (form : aexp) : aexp = + match form with + | Times lst -> + if List.filter notone lst = [] then Const 1 + else Times (Const 1 :: List.filter notone lst) + | Sum lst -> + if List.filter notzero lst = [] then Const 0 + else Sum (Const 0 :: List.filter notzero lst) + | _ -> form + + +let diff ((form : aexp), (var : string)) : aexp = arrange (cal (form, var)) diff --git a/OCaml/diff-26/buggy/test.ml b/OCaml/diff-26/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-26/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-26/buggy/testcases b/OCaml/diff-26/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-26/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-26/metadata.json b/OCaml/diff-26/metadata.json new file mode 100644 index 000000000..05d013dbd --- /dev/null +++ b/OCaml/diff-26/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-26", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-27/.dockerignore b/OCaml/diff-27/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-27/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-27/Dockerfile b/OCaml/diff-27/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-27/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-27/buggy/src.ml b/OCaml/diff-27/buggy/src.ml new file mode 100644 index 000000000..0e0f5685a --- /dev/null +++ b/OCaml/diff-27/buggy/src.ml @@ -0,0 +1,112 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let diff ((f : aexp), (v : string)) : aexp = + let rec deployEnv (env : (string * int * int) list) (o : int) : aexp list = + match env with + | a :: b -> ( + match a with + | x, c, p -> + if o = 0 && c = 0 then deployEnv b o + else if x = "const" && o = 1 && c = 1 then deployEnv b o + else if p = 0 then Const c :: deployEnv b o + else if c = 1 && p = 1 then Var x :: deployEnv b o + else if p = 1 then Times [ Const c; Var x ] :: deployEnv b o + else if c = 1 then Power (x, p) :: deployEnv b o + else Times [ Const c; Power (x, p) ] :: deployEnv b o ) + | [] -> [] + in + + let rec updateEnv (o : int) (e : string * int * int) + (env : (string * int * int) list) : (string * int * int) list = + match env with + | hd :: tl -> ( + match hd with + | s, c, p -> ( + match e with + | s2, c2, p2 -> + if o = 0 then + if s = s2 && p = p2 then (s, c + c2, p) :: tl + else hd :: updateEnv o e tl + else if s = s2 then (s, c * c2, p + p2) :: tl + else hd :: updateEnv o e tl ) ) + | [] -> [ e ] + in + + let rec doDiff ((f : aexp), (v : string)) : aexp = + match f with + | Const _ -> Const 0 + | Var x -> if x = v then Const 1 else Const 0 + | Power (x, p) -> + if p = 0 then Const 0 + else if x = v then Times [ Const p; Power (x, p - 1) ] + else Const 0 + | Times x -> ( + match x with + | [ a ] -> doDiff (a, v) + | a :: b -> ( + let da : aexp = doDiff (a, v) in + + let db : aexp = doDiff (Times b, v) in + + match (a, db, b, da) with + | Const p, Const q, [ Const r ], Const s -> Const ((p * q) + (r * s)) + | Const p, Const q, _, _ -> + if da = Const 0 || b = [ Const 0 ] then Const (p * q) + else Sum [ Const (p * q); Times (da :: b) ] + | _, _, [ Const r ], Const s -> + if a = Const 0 || db = Const 0 then Const (r * s) + else Sum [ Times [ a; db ]; Const (r * s) ] + | _ -> + if a = Const 0 || db = Const 0 then Times (da :: b) + else if b = [ Const 0 ] || da = Const 0 then Times [ a; db ] + else Sum [ Times [ a; db ]; Times (da :: b) ] ) + | [] -> Const 0 ) + | Sum x -> Sum (List.map (fun (x : aexp) -> doDiff (x, v)) x) + in + + let rec prettyAE (f : aexp) (env : (string * int * int) list) (o : int) : + aexp list = + match f with + | Sum x -> ( + match x with + | Const a :: z -> prettyAE (Sum z) (updateEnv 0 ("const", a, 0) env) 0 + | Var a :: z -> prettyAE (Sum z) (updateEnv 0 (a, 1, 1) env) 0 + | Power (a, b) :: z -> prettyAE (Sum z) (updateEnv 0 (a, 1, b) env) 0 + | Sum y :: z -> prettyAE (Sum (List.append y z)) env 0 + | Times y :: z -> ( + let l : aexp list = prettyAE (Times y) [] 1 in + + match l with + | h :: t -> + if t = [] then List.append l (prettyAE (Sum z) env 0) + else List.append [ Times l ] (prettyAE (Sum z) env 0) + | [] -> [] ) + | [] -> deployEnv env 0 ) + | Times x -> ( + match x with + | Const a :: z -> prettyAE (Times z) (updateEnv 1 ("const", a, 0) env) 1 + | Var a :: z -> prettyAE (Times z) (updateEnv 1 (a, 1, 1) env) 1 + | Power (a, b) :: z -> prettyAE (Times z) (updateEnv 1 (a, 1, b) env) 1 + | Sum y :: z -> ( + let l : aexp list = prettyAE (Sum y) [] 0 in + + match l with + | h :: t -> + if t = [] then List.append l (prettyAE (Times z) env 1) + else List.append [ Sum l ] (prettyAE (Times z) env 1) + | [] -> [] ) + | Times y :: z -> prettyAE (Times (List.append y z)) env 1 + | [] -> deployEnv env 1 ) + in + + let res : aexp = doDiff (f, v) in + + match res with + | Sum _ -> Sum (prettyAE res [] 0) + | Times _ -> Times (prettyAE res [] 1) + | _ -> res diff --git a/OCaml/diff-27/buggy/test.ml b/OCaml/diff-27/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-27/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-27/buggy/testcases b/OCaml/diff-27/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-27/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-27/metadata.json b/OCaml/diff-27/metadata.json new file mode 100644 index 000000000..1c7871bb3 --- /dev/null +++ b/OCaml/diff-27/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-27", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-28/.dockerignore b/OCaml/diff-28/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-28/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-28/Dockerfile b/OCaml/diff-28/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-28/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-28/buggy/src.ml b/OCaml/diff-28/buggy/src.ml new file mode 100644 index 000000000..85f55b957 --- /dev/null +++ b/OCaml/diff-28/buggy/src.ml @@ -0,0 +1,57 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((a : aexp), (str : string)) : aexp = + match a with + | Const n -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, n) -> + if s = str then + if n = 2 then Times [ Const 2; Var s ] + else if n = 1 then Const 1 + else if n = 0 then Const 0 + else Times [ Const n; Power (s, n - 1) ] + else Const 0 + | Times [] -> raise InvalidArgument + | Times aexps -> + let clean (aexps : aexp list) : aexp = + if List.mem (Const 0) aexps then Const 0 + else + let filt : aexp list = + List.filter (fun (x : aexp) -> x != Const 1) aexps + in + if List.length filt = 0 then Const 0 + else if List.length filt = 1 then List.hd filt + else Times filt + in + + let new_aexps : aexp list = + List.filter + (fun (n : aexp) -> n != Const 0) + (List.map + (fun (x : aexp) -> + clean + (List.map + (fun (y : aexp) -> if x = y then diff (y, str) else y) + aexps)) + aexps) + in + if List.length new_aexps = 0 then Const 0 + else if List.length new_aexps = 1 then List.hd new_aexps + else Sum new_aexps + | Sum [] -> raise InvalidArgument + | Sum aexps -> + let new_aexps : aexp list = + List.filter + (fun (n : aexp) -> n != Const 0) + (List.map (fun (x : aexp) -> diff (x, str)) aexps) + in + if List.length new_aexps = 0 then Const 0 + else if List.length new_aexps = 1 then List.hd new_aexps + else Sum new_aexps diff --git a/OCaml/diff-28/buggy/test.ml b/OCaml/diff-28/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-28/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-28/buggy/testcases b/OCaml/diff-28/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-28/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-28/metadata.json b/OCaml/diff-28/metadata.json new file mode 100644 index 000000000..57b7aa0af --- /dev/null +++ b/OCaml/diff-28/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-28", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-29/.dockerignore b/OCaml/diff-29/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-29/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-29/Dockerfile b/OCaml/diff-29/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-29/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-29/buggy/src.ml b/OCaml/diff-29/buggy/src.ml new file mode 100644 index 000000000..8d9458078 --- /dev/null +++ b/OCaml/diff-29/buggy/src.ml @@ -0,0 +1,59 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff_temp ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var str1 -> if str1 = str then Const 1 else Const 0 + | Power (str1, n) -> + if str1 = str then Times [ Const n; Power (str1, n - 1) ] else Const 0 + | Times aexplist -> + if List.tl aexplist = [] then diff_temp (List.hd aexplist, str) + else + Sum + [ + Times + [ diff_temp (List.hd aexplist, str); Times (List.tl aexplist) ]; + Times + [ List.hd aexplist; diff_temp (Times (List.tl aexplist), str) ]; + ] + | Sum aexplist -> + if List.tl aexplist = [] then diff_temp (List.hd aexplist, str) + else + Sum + [ + diff_temp (List.hd aexplist, str); + diff_temp (Sum (List.tl aexplist), str); + ] + + +let diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var str1 -> if str1 = str then Const 1 else Const 0 + | Power (str1, n) -> + if str1 = str then Times [ Const n; Power (str1, n - 1) ] else Const 0 + | Times aexplist -> + if aexplist = [] then raise InvalidArgument + else + Sum + [ + Times + [ diff_temp (List.hd aexplist, str); Times (List.tl aexplist) ]; + Times + [ List.hd aexplist; diff_temp (Times (List.tl aexplist), str) ]; + ] + | Sum aexplist -> + if aexplist = [] then raise InvalidArgument + else + Sum + [ + diff_temp (List.hd aexplist, str); + diff_temp (Sum (List.tl aexplist), str); + ] diff --git a/OCaml/diff-29/buggy/test.ml b/OCaml/diff-29/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-29/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-29/buggy/testcases b/OCaml/diff-29/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-29/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-29/metadata.json b/OCaml/diff-29/metadata.json new file mode 100644 index 000000000..e52f193ce --- /dev/null +++ b/OCaml/diff-29/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-29", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-3/.dockerignore b/OCaml/diff-3/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-3/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-3/Dockerfile b/OCaml/diff-3/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-3/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-3/buggy/src.ml b/OCaml/diff-3/buggy/src.ml new file mode 100644 index 000000000..80933b244 --- /dev/null +++ b/OCaml/diff-3/buggy/src.ml @@ -0,0 +1,29 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((a : aexp), (s : string)) : aexp = + match a with + | Const i -> Const 0 + | Var v -> if v = s then Const 1 else Const 0 + | Power (v, p) -> + if v != s || p = 0 then Const 0 + else if p = 1 then Const 1 + else Times [ Const p; Power (v, p - 1) ] + | Times l -> + Sum + (List.map + (fun (x : aexp) -> + if diff (x, s) = Const 0 then Const 0 + else if diff (x, s) = Const 1 then + Times (List.filter (fun (y : aexp) -> y != x) l) + else Times (diff (x, s) :: List.filter (fun (y : aexp) -> y != x) l)) + l) + | Sum l -> + Sum + (List.filter + (fun (x : aexp) -> x != Const 0) + (List.map (fun (x : aexp) -> diff (x, s)) l)) diff --git a/OCaml/diff-3/buggy/test.ml b/OCaml/diff-3/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-3/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-3/buggy/testcases b/OCaml/diff-3/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-3/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-3/metadata.json b/OCaml/diff-3/metadata.json new file mode 100644 index 000000000..0649a6cc9 --- /dev/null +++ b/OCaml/diff-3/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-3", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-30/.dockerignore b/OCaml/diff-30/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-30/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-30/Dockerfile b/OCaml/diff-30/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-30/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-30/buggy/src.ml b/OCaml/diff-30/buggy/src.ml new file mode 100644 index 000000000..3aa1ba81f --- /dev/null +++ b/OCaml/diff-30/buggy/src.ml @@ -0,0 +1,32 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((aexp : aexp), (s : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var x -> if s = x then Const 1 else Const 0 + | Power (x, n) -> + if s = x then + if n = 0 then Const 0 + else if n = 1 then Const 1 + else Times [ Const n; Power (x, n - 1) ] + else Power (x, n) + | Times aexpl -> + if List.length aexpl = 0 then raise InvalidArgument + else if List.length aexpl = 1 then diff (List.hd aexpl, s) + else + Sum + [ + Times (diff (List.hd aexpl, s) :: List.tl aexpl); + Times [ List.hd aexpl; diff (Times (List.tl aexpl), s) ]; + ] + | Sum aexpl -> + if List.length aexpl = 0 then raise InvalidArgument + else if List.length aexpl = 1 then diff (List.hd aexpl, s) + else Sum [ diff (List.hd aexpl, s); diff (Sum (List.tl aexpl), s) ] diff --git a/OCaml/diff-30/buggy/test.ml b/OCaml/diff-30/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-30/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-30/buggy/testcases b/OCaml/diff-30/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-30/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-30/metadata.json b/OCaml/diff-30/metadata.json new file mode 100644 index 000000000..6b39dd013 --- /dev/null +++ b/OCaml/diff-30/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-30", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-31/.dockerignore b/OCaml/diff-31/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-31/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-31/Dockerfile b/OCaml/diff-31/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-31/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-31/buggy/src.ml b/OCaml/diff-31/buggy/src.ml new file mode 100644 index 000000000..3aa1ba81f --- /dev/null +++ b/OCaml/diff-31/buggy/src.ml @@ -0,0 +1,32 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((aexp : aexp), (s : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var x -> if s = x then Const 1 else Const 0 + | Power (x, n) -> + if s = x then + if n = 0 then Const 0 + else if n = 1 then Const 1 + else Times [ Const n; Power (x, n - 1) ] + else Power (x, n) + | Times aexpl -> + if List.length aexpl = 0 then raise InvalidArgument + else if List.length aexpl = 1 then diff (List.hd aexpl, s) + else + Sum + [ + Times (diff (List.hd aexpl, s) :: List.tl aexpl); + Times [ List.hd aexpl; diff (Times (List.tl aexpl), s) ]; + ] + | Sum aexpl -> + if List.length aexpl = 0 then raise InvalidArgument + else if List.length aexpl = 1 then diff (List.hd aexpl, s) + else Sum [ diff (List.hd aexpl, s); diff (Sum (List.tl aexpl), s) ] diff --git a/OCaml/diff-31/buggy/test.ml b/OCaml/diff-31/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-31/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-31/buggy/testcases b/OCaml/diff-31/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-31/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-31/metadata.json b/OCaml/diff-31/metadata.json new file mode 100644 index 000000000..86e016bf4 --- /dev/null +++ b/OCaml/diff-31/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-31", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-32/.dockerignore b/OCaml/diff-32/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-32/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-32/Dockerfile b/OCaml/diff-32/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-32/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-32/buggy/src.ml b/OCaml/diff-32/buggy/src.ml new file mode 100644 index 000000000..7328940ad --- /dev/null +++ b/OCaml/diff-32/buggy/src.ml @@ -0,0 +1,8 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = aexp diff --git a/OCaml/diff-32/buggy/test.ml b/OCaml/diff-32/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-32/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-32/buggy/testcases b/OCaml/diff-32/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-32/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-32/metadata.json b/OCaml/diff-32/metadata.json new file mode 100644 index 000000000..0250909e7 --- /dev/null +++ b/OCaml/diff-32/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-32", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-33/.dockerignore b/OCaml/diff-33/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-33/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-33/Dockerfile b/OCaml/diff-33/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-33/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-33/buggy/src.ml b/OCaml/diff-33/buggy/src.ml new file mode 100644 index 000000000..58f591197 --- /dev/null +++ b/OCaml/diff-33/buggy/src.ml @@ -0,0 +1,60 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec exist ((l : aexp list), (x : string)) : int = + match l with + | [] -> 0 + | hd :: tl -> ( + match hd with + | Var v -> if v = x then 1 + exist (tl, x) else exist (tl, x) + | Power (str, i) -> if str = x then 1 + exist (tl, x) else exist (tl, x) + | Times lst -> exist (lst, x) + exist (tl, x) + | Sum lst -> exist (lst, x) + exist (tl, x) + | _ -> 0 + exist (tl, x) ) + + +let rec modify ((l : aexp list), (x : string)) : aexp list = + match l with + | [] -> [] + | hd :: tl -> ( + match hd with + | Const n -> Times [ Power (x, 0); Const n ] :: modify (tl, x) + | _ -> hd :: modify (tl, x) ) + + +let normalized ((l : aexp), (x : string)) : aexp = + let modified : aexp list = modify ([ l ], x) in + + match modified with [] -> raise (Failure "error") | hd :: tl -> hd + + +let rec diff ((aexp : aexp), (x : string)) : aexp = + if exist ([ aexp ], x) > 0 then + match aexp with + | Const n -> Const 0 + | Var str -> Const 1 + | Power (str, n) -> Times [ Const n; Power (str, n - 1) ] + | Times l -> ( + match l with + | [] -> Const 1 + | hd :: tl -> ( + match hd with + | Const n -> Times [ Const n; diff (Times tl, x) ] + | Power (str1, n1) -> + if n1 = 0 then Times [ Const 0; diff (Times tl, x) ] + else Times [ diff (hd, x); diff (Times tl, x) ] + | _ -> Times [ diff (hd, x); diff (Times tl, x) ] ) ) + | Sum l -> ( + let mod_exp : aexp = normalized (aexp, x) in + + match mod_exp with + | Sum l1 -> ( + match l1 with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) + | _ -> raise (Failure "error") ) + else match aexp with Times [] -> Const 1 | _ -> Const 0 diff --git a/OCaml/diff-33/buggy/test.ml b/OCaml/diff-33/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-33/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-33/buggy/testcases b/OCaml/diff-33/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-33/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-33/metadata.json b/OCaml/diff-33/metadata.json new file mode 100644 index 000000000..54ec21691 --- /dev/null +++ b/OCaml/diff-33/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-33", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-34/.dockerignore b/OCaml/diff-34/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-34/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-34/Dockerfile b/OCaml/diff-34/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-34/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-34/buggy/src.ml b/OCaml/diff-34/buggy/src.ml new file mode 100644 index 000000000..846aa960e --- /dev/null +++ b/OCaml/diff-34/buggy/src.ml @@ -0,0 +1,32 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var alpha -> if alpha = x then Const 1 else aexp + | Power (alpha, a) -> + if alpha = x then Times [ Const a; Power (alpha, a - 1) ] else aexp + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> ( + match tl with + | [] -> diff (hd, x) + | _ -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) ) + | Times lst -> ( + match lst with + | [] -> Const 1 + | hd :: tl -> ( + match tl with + | [] -> diff (hd, x) + | _ -> + Sum + [ + Times [ diff (hd, x); Times tl ]; + Times [ hd; diff (Times tl, x) ]; + ] ) ) diff --git a/OCaml/diff-34/buggy/test.ml b/OCaml/diff-34/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-34/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-34/buggy/testcases b/OCaml/diff-34/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-34/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-34/metadata.json b/OCaml/diff-34/metadata.json new file mode 100644 index 000000000..361a39545 --- /dev/null +++ b/OCaml/diff-34/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-34", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-35/.dockerignore b/OCaml/diff-35/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-35/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-35/Dockerfile b/OCaml/diff-35/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-35/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-35/buggy/src.ml b/OCaml/diff-35/buggy/src.ml new file mode 100644 index 000000000..14e14bfd9 --- /dev/null +++ b/OCaml/diff-35/buggy/src.ml @@ -0,0 +1,21 @@ +type aexp = + | Const of int + | Var of string + | Power of string * int + | Times of aexp list + | Sum of aexp list + +let rec map f l x= +match l with +| [] -> [] +| hd::tl -> (f (hd, x))::(map f tl x) + +let rec diff : aexp * string -> aexp +=fun (aexp,x) -> match aexp with +Const n -> Const 0 +|Var s -> if (s = x) then Const 1 else Const 0 +|Power (s, n) -> if (s = x) then Times ([Const n] @ [Power (s, n-1)]) else Const 0 +|Times [] -> Times [] +|Times (hd::tl::[]) -> Sum ([Times ([diff (hd, x)] @ [tl])] @ [Times ([hd] @ [diff (tl, x)])]) +|Times (hd::tl) -> Sum ([Times ([diff (hd, x)] @ tl)] @ [Times ([hd] @ [diff (Times tl, x)])]) +|Sum lst -> Sum (map diff lst x) diff --git a/OCaml/diff-35/buggy/test.ml b/OCaml/diff-35/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-35/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-35/buggy/testcases b/OCaml/diff-35/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-35/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-35/metadata.json b/OCaml/diff-35/metadata.json new file mode 100644 index 000000000..6e9741b29 --- /dev/null +++ b/OCaml/diff-35/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-35", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-36/.dockerignore b/OCaml/diff-36/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-36/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-36/Dockerfile b/OCaml/diff-36/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-36/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-36/buggy/src.ml b/OCaml/diff-36/buggy/src.ml new file mode 100644 index 000000000..78c04d119 --- /dev/null +++ b/OCaml/diff-36/buggy/src.ml @@ -0,0 +1,54 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec find_ch ((l : aexp list), (x : string)) : bool = + match l with + | [] -> false + | hd :: tl -> ( + match hd with + | Var str -> if str = x then true else find_ch (tl, x) + | Power (str, _) -> if str = x then true else find_ch (tl, x) + | _ -> find_ch (tl, x) ) + + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Sum l -> ( + match l with + | [] -> Const 0 + | [ hd ] -> diff (hd, x) + | hd :: tl -> Sum ([ diff (hd, x) ] @ [ diff (Sum tl, x) ]) ) + | Times l -> + if find_ch (l, x) then + match l with + | [] -> Const 0 + | hd :: tl -> ( + match hd with + | Const n -> Times ([ Const n ] @ [ diff (Times tl, x) ]) + | Var v -> + if v = x then + match tl with + | [] -> diff (Var v, x) + | _ -> diff (Times (tl @ [ Var v ]), x) + else Times ([ Var v ] @ [ diff (Times tl, x) ]) + | Power (v, n) -> + if v = x then + match tl with + | [] -> diff (Power (v, n), x) + | _ -> diff (Times (tl @ [ Power (v, n) ]), x) + else Times ([ Power (v, n) ] @ [ diff (Times tl, x) ]) + | _ -> Times l ) + else Const 0 + | Var v -> if v = x then Const 1 else Const 0 + | Power (v, n) -> + if v = x then + match n with + | 1 -> Const 1 + | 2 -> Times ([ Const 2 ] @ [ Var v ]) + | _ -> Times ([ Const n ] @ [ Power (v, n - 1) ]) + else Const 0 + | Const n -> Const 0 diff --git a/OCaml/diff-36/buggy/test.ml b/OCaml/diff-36/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-36/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-36/buggy/testcases b/OCaml/diff-36/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-36/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-36/metadata.json b/OCaml/diff-36/metadata.json new file mode 100644 index 000000000..b889e4e23 --- /dev/null +++ b/OCaml/diff-36/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-36", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-37/.dockerignore b/OCaml/diff-37/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-37/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-37/Dockerfile b/OCaml/diff-37/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-37/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-37/buggy/src.ml b/OCaml/diff-37/buggy/src.ml new file mode 100644 index 000000000..257e8b1a1 --- /dev/null +++ b/OCaml/diff-37/buggy/src.ml @@ -0,0 +1,51 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var x -> if x = str then Const 1 else Const 0 + | Power (x, n) -> + if n = 1 then Const 1 + else if x = str then Times [ Const n; Power (x, n - 1) ] + else Const 0 + | Times alist -> ( + match alist with + | [] -> raise (Failure "Empty List") + | [ hd ] -> diff (hd, str) + | hd :: tl -> ( + match hd with + | Const 0 -> Const 0 + | Const 1 -> diff (Times tl, str) + | Const n -> Times [ hd; diff (Times tl, str) ] + | Var x -> Times [ diff (hd, str); diff (Times tl, str) ] + | Power (x, n) -> + Times [ diff (Power (x, n), str); diff (Times tl, str) ] + | Times alist2 -> + Sum + [ + Times [ diff (Times alist2, str); Times tl ]; + Times [ Times alist2; diff (Times tl, str) ]; + ] + | Sum alist2 -> + Sum + [ + Times [ diff (Sum alist2, str); Times tl ]; + Times [ Sum alist2; diff (Times tl, str) ]; + ] ) ) + | Sum alist -> ( + match alist with + | [] -> raise (Failure "Empty List") + | [ hd ] -> diff (hd, str) + | hd :: tl -> ( + match hd with + | Const 0 -> Const 0 + | Const n -> diff (Sum tl, str) + | Var x -> Sum [ diff (Var x, str); diff (Sum tl, str) ] + | Power (x, n) -> Sum [ diff (Power (x, n), str); diff (Sum tl, str) ] + | Times alist2 -> Sum [ diff (Times alist2, str); diff (Sum tl, str) ] + | Sum alist2 -> Sum [ diff (Sum alist2, str); diff (Sum tl, str) ] ) ) diff --git a/OCaml/diff-37/buggy/test.ml b/OCaml/diff-37/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-37/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-37/buggy/testcases b/OCaml/diff-37/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-37/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-37/metadata.json b/OCaml/diff-37/metadata.json new file mode 100644 index 000000000..23916d33c --- /dev/null +++ b/OCaml/diff-37/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-37", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-38/.dockerignore b/OCaml/diff-38/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-38/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-38/Dockerfile b/OCaml/diff-38/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-38/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-38/buggy/src.ml b/OCaml/diff-38/buggy/src.ml new file mode 100644 index 000000000..1eaf1e4b2 --- /dev/null +++ b/OCaml/diff-38/buggy/src.ml @@ -0,0 +1,30 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var s -> if s = x then Const 1 else Const 0 + | Power (s, i) -> + if s = x then + match i with + | 0 -> Const 0 + | 1 -> Const 1 + | 2 -> Times [ Const 2; Var s ] + | _ -> Times [ Const i; Power ("x", i - 1) ] + else Const 0 + | Times l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> + Sum + ( [ Times ([ diff (hd, x) ] @ tl) ] + @ [ Times ([ hd ] @ [ diff (Times tl, x) ]) ] ) ) + | Sum l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> Sum ([ diff (hd, x) ] @ [ diff (Sum tl, x) ]) ) diff --git a/OCaml/diff-38/buggy/test.ml b/OCaml/diff-38/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-38/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-38/buggy/testcases b/OCaml/diff-38/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-38/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-38/metadata.json b/OCaml/diff-38/metadata.json new file mode 100644 index 000000000..f5e0e0e74 --- /dev/null +++ b/OCaml/diff-38/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-38", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-39/.dockerignore b/OCaml/diff-39/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-39/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-39/Dockerfile b/OCaml/diff-39/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-39/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-39/buggy/src.ml b/OCaml/diff-39/buggy/src.ml new file mode 100644 index 000000000..ea266d17f --- /dev/null +++ b/OCaml/diff-39/buggy/src.ml @@ -0,0 +1,30 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var v -> if v = x then Const 1 else Const 0 + | Power (v, n) -> + if v = x then + if n = 1 then Var v else Times [ Const n; Power ("x", n - 1) ] + else Const 0 + | Times l -> ( + match l with + | [] -> Times [] + | h :: t -> ( + match (h, t) with + | _, [] -> diff (h, x) + | Const 0, _ -> Const 0 + | _, _ -> + Sum [ Times (diff (h, x) :: t); Times [ h; diff (Times t, x) ] ] ) + ) + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> + if t = [] then diff (h, x) else Sum [ diff (h, x); diff (Sum t, x) ] ) diff --git a/OCaml/diff-39/buggy/test.ml b/OCaml/diff-39/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-39/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-39/buggy/testcases b/OCaml/diff-39/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-39/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-39/metadata.json b/OCaml/diff-39/metadata.json new file mode 100644 index 000000000..9d354a4db --- /dev/null +++ b/OCaml/diff-39/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-39", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-4/.dockerignore b/OCaml/diff-4/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-4/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-4/Dockerfile b/OCaml/diff-4/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-4/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-4/buggy/src.ml b/OCaml/diff-4/buggy/src.ml new file mode 100644 index 000000000..d2f706d0a --- /dev/null +++ b/OCaml/diff-4/buggy/src.ml @@ -0,0 +1,18 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var v -> if v = x then Const 1 else Const 0 + | Power (v, n) -> + if v = x then Times [ Const n; Power (v, n - 1) ] else Const 0 + | Sum l -> + let rec lstRec2 (l : aexp list) : aexp = + match l with [] -> Const 0 | h :: t -> Sum [ diff (h, x); lstRec2 t ] + in + lstRec2 l diff --git a/OCaml/diff-4/buggy/test.ml b/OCaml/diff-4/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-4/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-4/buggy/testcases b/OCaml/diff-4/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-4/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-4/metadata.json b/OCaml/diff-4/metadata.json new file mode 100644 index 000000000..a9b075e38 --- /dev/null +++ b/OCaml/diff-4/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-4", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-40/.dockerignore b/OCaml/diff-40/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-40/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-40/Dockerfile b/OCaml/diff-40/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-40/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-40/buggy/src.ml b/OCaml/diff-40/buggy/src.ml new file mode 100644 index 000000000..72262e8c5 --- /dev/null +++ b/OCaml/diff-40/buggy/src.ml @@ -0,0 +1,34 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff_times ((lst : aexp list), (x : string), (b : int)) : aexp = + match lst with + | [] -> Const 0 + | hd :: tl -> ( + match hd with + | Const a -> diff_times (tl, x, a + b) + | Var a -> if a = x then Const b else diff_times (tl, x, b) + | Power (a, k) -> + if a = x then + if k > 1 then Times [ Const (b * k); Power (a, k - 1) ] + else Const (b * k) + else Const 0 + | _ -> diff_times (tl, x, b) ) + + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Sum lst -> + Sum + ( match lst with + | [] -> [] + | hd :: tl -> [ diff (hd, x); diff (Sum tl, x) ] ) + | Times lst -> diff_times (lst, x, 0) + | Var a -> if a = x then Const 1 else Const 0 + | Const a -> Const 0 + | Power (a, b) -> + if b > 1 then Times [ Const b; Power (a, b - 1) ] else Const b diff --git a/OCaml/diff-40/buggy/test.ml b/OCaml/diff-40/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-40/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-40/buggy/testcases b/OCaml/diff-40/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-40/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-40/metadata.json b/OCaml/diff-40/metadata.json new file mode 100644 index 000000000..72b16381d --- /dev/null +++ b/OCaml/diff-40/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-40", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-41/.dockerignore b/OCaml/diff-41/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-41/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-41/Dockerfile b/OCaml/diff-41/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-41/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-41/buggy/src.ml b/OCaml/diff-41/buggy/src.ml new file mode 100644 index 000000000..76df5044e --- /dev/null +++ b/OCaml/diff-41/buggy/src.ml @@ -0,0 +1,22 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var a -> if a = x then Const 1 else Const 0 + | Power (a, b) -> + if a = x then Times [ Const b; Power (a, b - 1) ] else Const 0 + | Times l -> ( + match l with + | [] -> Const 0 + | [ hd ] -> diff (hd, x) + | hd :: tl -> + Sum [ Times [ hd; diff (Sum tl, x) ]; Times (diff (hd, x) :: tl) ] ) + | Sum l -> + let iterSum (a : aexp) : aexp = diff (a, x) in + Sum (List.map iterSum l) diff --git a/OCaml/diff-41/buggy/test.ml b/OCaml/diff-41/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-41/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-41/buggy/testcases b/OCaml/diff-41/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-41/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-41/metadata.json b/OCaml/diff-41/metadata.json new file mode 100644 index 000000000..fed34ffe5 --- /dev/null +++ b/OCaml/diff-41/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-41", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-42/.dockerignore b/OCaml/diff-42/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-42/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-42/Dockerfile b/OCaml/diff-42/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-42/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-42/buggy/src.ml b/OCaml/diff-42/buggy/src.ml new file mode 100644 index 000000000..7328940ad --- /dev/null +++ b/OCaml/diff-42/buggy/src.ml @@ -0,0 +1,8 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = aexp diff --git a/OCaml/diff-42/buggy/test.ml b/OCaml/diff-42/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-42/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-42/buggy/testcases b/OCaml/diff-42/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-42/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-42/metadata.json b/OCaml/diff-42/metadata.json new file mode 100644 index 000000000..c32aec324 --- /dev/null +++ b/OCaml/diff-42/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-42", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-43/.dockerignore b/OCaml/diff-43/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-43/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-43/Dockerfile b/OCaml/diff-43/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-43/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-43/buggy/src.ml b/OCaml/diff-43/buggy/src.ml new file mode 100644 index 000000000..7a8583c5e --- /dev/null +++ b/OCaml/diff-43/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var str -> if str = x then Const 1 else Const 0 + | Power (str, n) -> + if str = x then Times [ Const n; Power (x, n - 1) ] else Const 0 + | Times l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> + if hd = Const 0 then Const 0 + else + Sum + ( [ Times ([ diff (hd, x) ] @ tl) ] + @ [ Times ([ hd ] @ [ diff (Times tl, x) ]) ] ) ) + | Sum l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> + if hd = Const 0 then Sum tl + else Sum ([ diff (hd, x) ] @ [ Sum [ diff (Sum tl, x) ] ]) ) diff --git a/OCaml/diff-43/buggy/test.ml b/OCaml/diff-43/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-43/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-43/buggy/testcases b/OCaml/diff-43/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-43/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-43/metadata.json b/OCaml/diff-43/metadata.json new file mode 100644 index 000000000..d2cca5974 --- /dev/null +++ b/OCaml/diff-43/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-43", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-44/.dockerignore b/OCaml/diff-44/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-44/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-44/Dockerfile b/OCaml/diff-44/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-44/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-44/buggy/src.ml b/OCaml/diff-44/buggy/src.ml new file mode 100644 index 000000000..ab4eb18a0 --- /dev/null +++ b/OCaml/diff-44/buggy/src.ml @@ -0,0 +1,16 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Sum list1 -> ( match list1 with hd :: tl -> hd ) + | Const x -> Const x + | Var y -> Var y + | Power (z1, z2) -> + if z2 = 2 then Times [ Const z2; Var z1 ] + else Times [ Const z2; Power (z1, z2 - 1) ] + | Times list2 -> Const 2 diff --git a/OCaml/diff-44/buggy/test.ml b/OCaml/diff-44/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-44/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-44/buggy/testcases b/OCaml/diff-44/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-44/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-44/metadata.json b/OCaml/diff-44/metadata.json new file mode 100644 index 000000000..c40a72be1 --- /dev/null +++ b/OCaml/diff-44/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-44", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-45/.dockerignore b/OCaml/diff-45/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-45/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-45/Dockerfile b/OCaml/diff-45/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-45/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-45/buggy/src.ml b/OCaml/diff-45/buggy/src.ml new file mode 100644 index 000000000..9b97a0d80 --- /dev/null +++ b/OCaml/diff-45/buggy/src.ml @@ -0,0 +1,35 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (y : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var x -> if x = y then Const 1 else Const 0 + | Power (x, a) -> + if x = y then + if a = 0 then Const 0 + else if a = 1 then Const 1 + else Times [ Const a; Power (x, a - 1) ] + else Const 0 + | Times l -> ( + if List.mem (Const 0) l then Const 0 + else + match l with + | [ hd ] -> diff (aexp, y) + | hd :: tl -> ( + match hd with + | Const a -> Times [ hd; diff (Times tl, y) ] + | _ -> + Sum + [ + Times [ diff (hd, y); Times tl ]; + Times [ hd; diff (Times tl, y) ]; + ] ) ) + | Sum l -> ( + match l with + | [ hd ] -> diff (hd, y) + | hd :: tl -> Sum [ diff (hd, y); diff (Sum tl, y) ] ) diff --git a/OCaml/diff-45/buggy/test.ml b/OCaml/diff-45/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-45/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-45/buggy/testcases b/OCaml/diff-45/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-45/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-45/metadata.json b/OCaml/diff-45/metadata.json new file mode 100644 index 000000000..47c1d67e3 --- /dev/null +++ b/OCaml/diff-45/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-45", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-46/.dockerignore b/OCaml/diff-46/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-46/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-46/Dockerfile b/OCaml/diff-46/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-46/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-46/buggy/src.ml b/OCaml/diff-46/buggy/src.ml new file mode 100644 index 000000000..dd9758018 --- /dev/null +++ b/OCaml/diff-46/buggy/src.ml @@ -0,0 +1,34 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var x -> if x = x then Const 1 else Const 0 + | Power (x, n) -> + if x = x then + if n = 0 then Const 0 + else if n = 1 then Const 1 + else if n = 2 then Times [ Const 2; Var x ] + else Times [ Const n; Power (x, n - 1) ] + else Const 0 + | Times lst -> ( + match lst with + | [] -> Const 0 + | [ h ] -> diff (h, x) + | h :: t -> ( + match h with + | Const 1 -> diff (Times t, x) + | Const n -> Times [ h; diff (Times t, x) ] + | _ -> + Sum [ Times (diff (h, x) :: t); Times [ h; diff (Times t, x) ] ] ) + ) + | Sum lst2 -> ( + match lst2 with + | [] -> Const 0 + | [ h ] -> diff (h, x) + | h :: t -> Sum [ diff (h, x); diff (Sum t, x) ] ) diff --git a/OCaml/diff-46/buggy/test.ml b/OCaml/diff-46/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-46/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-46/buggy/testcases b/OCaml/diff-46/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-46/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-46/metadata.json b/OCaml/diff-46/metadata.json new file mode 100644 index 000000000..337f378b5 --- /dev/null +++ b/OCaml/diff-46/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-46", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-47/.dockerignore b/OCaml/diff-47/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-47/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-47/Dockerfile b/OCaml/diff-47/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-47/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-47/buggy/src.ml b/OCaml/diff-47/buggy/src.ml new file mode 100644 index 000000000..97379c019 --- /dev/null +++ b/OCaml/diff-47/buggy/src.ml @@ -0,0 +1,21 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var x -> Const 1 + | Power (x, n) -> ( + match n with + | 0 -> Const 1 + | _ -> Times [ Const n; diff (Power (x, n - 1), x) ] ) + | Times (a :: b :: tl) -> Times [ a; diff (b, x) ] + | Sum (hd :: tl) -> ( + match hd with + | Const 0 -> Const 0 + | _ -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) + | Times [] -> raise (Failure "error") diff --git a/OCaml/diff-47/buggy/test.ml b/OCaml/diff-47/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-47/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-47/buggy/testcases b/OCaml/diff-47/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-47/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-47/metadata.json b/OCaml/diff-47/metadata.json new file mode 100644 index 000000000..18956a4a1 --- /dev/null +++ b/OCaml/diff-47/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-47", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-48/.dockerignore b/OCaml/diff-48/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-48/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-48/Dockerfile b/OCaml/diff-48/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-48/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-48/buggy/src.ml b/OCaml/diff-48/buggy/src.ml new file mode 100644 index 000000000..46cf79c1a --- /dev/null +++ b/OCaml/diff-48/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var a -> Var a + | Power (a, b) -> if b = 1 then Var a else Times [ Const b; Power (a, b - 1) ] + | Times a -> ( + match a with + | hd :: tl -> ( + match hd with + | Const t -> + Times + [ Const t; Sum [ Times [ Const 1 ]; Times [ Var x; Const 0 ] ] ] + | Var t -> Times [ Var t; Const 0 ] ) ) + | Sum a -> ( + match a with + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] + | _ -> Const 0 ) diff --git a/OCaml/diff-48/buggy/test.ml b/OCaml/diff-48/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-48/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-48/buggy/testcases b/OCaml/diff-48/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-48/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-48/metadata.json b/OCaml/diff-48/metadata.json new file mode 100644 index 000000000..eddc51879 --- /dev/null +++ b/OCaml/diff-48/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-48", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-49/.dockerignore b/OCaml/diff-49/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-49/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-49/Dockerfile b/OCaml/diff-49/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-49/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-49/buggy/src.ml b/OCaml/diff-49/buggy/src.ml new file mode 100644 index 000000000..e86828e0a --- /dev/null +++ b/OCaml/diff-49/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var chars -> Var chars + | Power (chars, n) -> + if n > 2 then Times [ Const n; Power (chars, n - 1) ] + else Times [ Const n; Var chars ] + | Times lst -> ( + match lst with + | [] -> Const 0 + | aexp :: tl -> ( match aexp with Const n -> Const n ) ) + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd -> Const 0 + | hd :: tl -> Sum [ diff (hd, x); Sum tl ] ) diff --git a/OCaml/diff-49/buggy/test.ml b/OCaml/diff-49/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-49/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-49/buggy/testcases b/OCaml/diff-49/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-49/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-49/metadata.json b/OCaml/diff-49/metadata.json new file mode 100644 index 000000000..c32a5d794 --- /dev/null +++ b/OCaml/diff-49/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-49", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-5/.dockerignore b/OCaml/diff-5/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-5/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-5/Dockerfile b/OCaml/diff-5/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-5/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-5/buggy/src.ml b/OCaml/diff-5/buggy/src.ml new file mode 100644 index 000000000..240da8fb3 --- /dev/null +++ b/OCaml/diff-5/buggy/src.ml @@ -0,0 +1,45 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + let rec isThereStr (aexp : aexp) (str : string) : bool = + match aexp with + | Const i -> false + | Var s -> s = str + | Power (s, i) -> s = str + | Times l -> ( + match l with + | [] -> false + | h :: t -> isThereStr h str || isThereStr (Times t) str ) + | Sum l -> ( + match l with + | [] -> false + | h :: t -> isThereStr h str || isThereStr (Sum t) str ) + in + + let rec mul (al : aexp list) (str : string) : aexp list = + match al with + | [] -> [] + | [ h ] -> if isThereStr h str then [ diff (h, str) ] else [ h ] + | h :: t -> + if isThereStr h str then List.append [ diff (h, str) ] (mul t str) + else List.append [ h ] (mul t str) + in + + match aexp with + | Const i -> Const 0 + | Var s -> if s = str then Const 1 else Const 0 + | Power (s, i) -> + if s = str then + if i > 1 then Times [ Const i; Power (s, i - 1) ] else Const 1 + else Const 0 + | Times l -> if isThereStr aexp str then Times (mul l str) else Const 0 + | Sum l -> ( + match l with + | [] -> Const 0 + | [ h ] -> diff (h, str) + | h :: t -> Sum (List.append [ diff (h, str) ] [ diff (Sum t, str) ]) ) diff --git a/OCaml/diff-5/buggy/test.ml b/OCaml/diff-5/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-5/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-5/buggy/testcases b/OCaml/diff-5/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-5/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-5/metadata.json b/OCaml/diff-5/metadata.json new file mode 100644 index 000000000..e54cd5038 --- /dev/null +++ b/OCaml/diff-5/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-5", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-50/.dockerignore b/OCaml/diff-50/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-50/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-50/Dockerfile b/OCaml/diff-50/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-50/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-50/buggy/src.ml b/OCaml/diff-50/buggy/src.ml new file mode 100644 index 000000000..162bc06a6 --- /dev/null +++ b/OCaml/diff-50/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const b -> Const 0 + | Var a -> if x != a then Const 0 else Const 1 + | Power (a, b) -> + if x != a then Const 0 + else if b = 1 then diff (Var a, x) + else Times [ Const b; Power (a, b - 1) ] + | Times lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> Times [ hd; diff (Sum tl, x) ] ) + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) diff --git a/OCaml/diff-50/buggy/test.ml b/OCaml/diff-50/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-50/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-50/buggy/testcases b/OCaml/diff-50/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-50/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-50/metadata.json b/OCaml/diff-50/metadata.json new file mode 100644 index 000000000..2fb820ea7 --- /dev/null +++ b/OCaml/diff-50/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-50", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-51/.dockerignore b/OCaml/diff-51/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-51/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-51/Dockerfile b/OCaml/diff-51/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-51/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-51/buggy/src.ml b/OCaml/diff-51/buggy/src.ml new file mode 100644 index 000000000..28a3a2777 --- /dev/null +++ b/OCaml/diff-51/buggy/src.ml @@ -0,0 +1,17 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Power (a, b) -> Times [ Const b; Var a ] + | Const n -> Const 0 + | Var n -> Var n + | Times (hd :: tl) -> + Sum [ Times (diff (hd, x) :: tl); Times [ hd; diff (Times tl, x) ] ] + | Times [] -> Const 0 + | Sum (hd :: tl) -> Sum [ diff (hd, x); diff (Sum tl, x) ] + | Sum [] -> Const 0 diff --git a/OCaml/diff-51/buggy/test.ml b/OCaml/diff-51/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-51/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-51/buggy/testcases b/OCaml/diff-51/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-51/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-51/metadata.json b/OCaml/diff-51/metadata.json new file mode 100644 index 000000000..2acd4942d --- /dev/null +++ b/OCaml/diff-51/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-51", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-52/.dockerignore b/OCaml/diff-52/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-52/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-52/Dockerfile b/OCaml/diff-52/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-52/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-52/buggy/src.ml b/OCaml/diff-52/buggy/src.ml new file mode 100644 index 000000000..e464617e0 --- /dev/null +++ b/OCaml/diff-52/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const _ -> Const 0 + | Var x -> Const 1 + | Power (x, a) -> ( + match a with + | 0 -> Const 0 + | 1 -> Const 1 + | 2 -> Times [ Const 2; Var x ] + | _ -> Times [ Const a; Power (x, a - 1) ] ) + | Times l -> ( + match l with + | [] -> raise (Failure "NO INPUT") + | [ b ] -> diff (b, x) + | h :: t -> + Sum [ Times (diff (h, x) :: t); Times [ h; diff (Times t, x) ] ] ) + | Sum s -> ( + match s with + | [] -> raise (Failure "NO INPUT") + | [ b ] -> diff (b, x) + | h :: t -> Sum [ diff (h, x); diff (Sum t, x) ] ) diff --git a/OCaml/diff-52/buggy/test.ml b/OCaml/diff-52/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-52/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-52/buggy/testcases b/OCaml/diff-52/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-52/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-52/metadata.json b/OCaml/diff-52/metadata.json new file mode 100644 index 000000000..e2b08078d --- /dev/null +++ b/OCaml/diff-52/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-52", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-53/.dockerignore b/OCaml/diff-53/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-53/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-53/Dockerfile b/OCaml/diff-53/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-53/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-53/buggy/src.ml b/OCaml/diff-53/buggy/src.ml new file mode 100644 index 000000000..27042c815 --- /dev/null +++ b/OCaml/diff-53/buggy/src.ml @@ -0,0 +1,63 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((e : aexp), (v : string)) : aexp = + match e with + | Const n -> Const 0 + | Var x -> if x = v then Const 1 else Var x + | Power (x, i) -> + if i = 1 then Const 1 else Times [ Const i; Power (x, i - 1) ] + | Times al -> + let rec diff_times (el : aexp list) (x : string) : aexp list = + match el with + | [] -> [] + | Const c :: tl -> Const c :: diff_times tl x + | Times ts :: tl -> diff_times (List.append ts tl) x + | hd :: tl -> diff (hd, v) :: diff_times tl x + in + + let rec clean_times (rs : aexp list) (coef : int) : aexp list * int = + match rs with + | [] -> ([], coef) + | Const n :: tl -> clean_times tl (coef * n) + | hd :: tl -> + let (t0, m) : aexp list * int = clean_times tl coef in + (hd :: t0, m) + in + + let rec concat_times (ts : aexp list) : aexp list = + match ts with + | [] -> [] + | Times t1 :: tl -> concat_times (List.append t1 tl) + | hd :: tl -> hd :: concat_times tl + in + + let t1 : aexp list = diff_times al v in + + let t2 : aexp list = concat_times t1 in + + let (t3, n) : aexp list * int = clean_times t2 1 in + if n = 1 then Times t3 else Times (Const n :: t3) + | Sum al -> + let rec diff_list (el : aexp list) (x : string) : aexp list = + match el with [] -> [] | hd :: tl -> diff (hd, x) :: diff_list tl x + in + + let rec clean_sum (rs : aexp list) (con : int) : aexp list * int = + match rs with + | [] -> ([], con) + | Times [ a ] :: tl -> clean_sum (a :: tl) con + | Const n :: tl -> clean_sum tl (con + n) + | hd :: tl -> + let (ts, con1) : aexp list * int = clean_sum tl con in + (hd :: ts, con1) + in + + let s1 : aexp list = diff_list al v in + + let (s2, n) : aexp list * int = clean_sum s1 0 in + if n = 0 then Sum s2 else Sum (List.append s2 [ Const n ]) diff --git a/OCaml/diff-53/buggy/test.ml b/OCaml/diff-53/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-53/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-53/buggy/testcases b/OCaml/diff-53/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-53/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-53/metadata.json b/OCaml/diff-53/metadata.json new file mode 100644 index 000000000..f0e2d0281 --- /dev/null +++ b/OCaml/diff-53/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-53", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-54/.dockerignore b/OCaml/diff-54/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-54/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-54/Dockerfile b/OCaml/diff-54/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-54/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-54/buggy/src.ml b/OCaml/diff-54/buggy/src.ml new file mode 100644 index 000000000..7fd11ee1c --- /dev/null +++ b/OCaml/diff-54/buggy/src.ml @@ -0,0 +1,29 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec map (f : 'b -> 'a) (l : 'b list) : 'a list = + match l with [] -> [] | hd :: tl -> f hd :: map f tl + + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Sum l -> + Sum + ( match l with + | [] -> [ Const 0 ] + | hd :: tl -> [ diff (hd, x); diff (Sum tl, x) ] ) + | Const n -> Const 0 + | Var x -> Const 1 + | Power (x, n) -> ( + match n with 1 -> Const 1 | n -> Times [ Const n; Power (x, n - 1) ] ) + | Times l -> ( + match l with + | [] -> Const 0 + | [ Const a; Const b; ax ] -> Times [ Const (a * b); diff (ax, x) ] + | [ Const a; ax ] -> Times [ Const a; diff (ax, x) ] + | [ Const a ] -> Const 0 + | [ ax ] -> diff (ax, x) ) diff --git a/OCaml/diff-54/buggy/test.ml b/OCaml/diff-54/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-54/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-54/buggy/testcases b/OCaml/diff-54/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-54/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-54/metadata.json b/OCaml/diff-54/metadata.json new file mode 100644 index 000000000..edb8ec1db --- /dev/null +++ b/OCaml/diff-54/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-54", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-55/.dockerignore b/OCaml/diff-55/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-55/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-55/Dockerfile b/OCaml/diff-55/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-55/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-55/buggy/src.ml b/OCaml/diff-55/buggy/src.ml new file mode 100644 index 000000000..14449dd42 --- /dev/null +++ b/OCaml/diff-55/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var x -> if x = str then Const 1 else aexp + | Power (x, n) -> + if x = str then Times [ Const n; Power (x, n - 1) ] else aexp + | Times l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> + Sum + ( [ Times (diff (hd, str) :: tl) ] + @ [ Times [ hd; diff (Times tl, str) ] ] ) ) + | Sum l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> Sum ([ diff (hd, str) ] @ [ diff (Sum tl, str) ]) ) diff --git a/OCaml/diff-55/buggy/test.ml b/OCaml/diff-55/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-55/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-55/buggy/testcases b/OCaml/diff-55/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-55/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-55/metadata.json b/OCaml/diff-55/metadata.json new file mode 100644 index 000000000..57a34b4cb --- /dev/null +++ b/OCaml/diff-55/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-55", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-56/.dockerignore b/OCaml/diff-56/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-56/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-56/Dockerfile b/OCaml/diff-56/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-56/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-56/buggy/src.ml b/OCaml/diff-56/buggy/src.ml new file mode 100644 index 000000000..1d11485b9 --- /dev/null +++ b/OCaml/diff-56/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var s -> if s = x then Const 1 else Const 0 + | Power (s, a) -> + if a = 1 then Const 1 else Times [ Const a; Power (s, a - 1) ] + | Times lst -> ( + match lst with + | [] -> Const 0 + | h :: t -> + if t = [] then + Sum + [ Times [ diff (h, x); Const 1 ]; Times [ h; diff (Times t, x) ] ] + else + Sum + [ Times [ diff (h, x); Times t ]; Times [ h; diff (Times t, x) ] ] + ) + | Sum lst2 -> ( + match lst2 with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, x); diff (Sum t, x) ] ) diff --git a/OCaml/diff-56/buggy/test.ml b/OCaml/diff-56/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-56/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-56/buggy/testcases b/OCaml/diff-56/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-56/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-56/metadata.json b/OCaml/diff-56/metadata.json new file mode 100644 index 000000000..ed68a60c5 --- /dev/null +++ b/OCaml/diff-56/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-56", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-57/.dockerignore b/OCaml/diff-57/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-57/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-57/Dockerfile b/OCaml/diff-57/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-57/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-57/buggy/src.ml b/OCaml/diff-57/buggy/src.ml new file mode 100644 index 000000000..d970cfdc3 --- /dev/null +++ b/OCaml/diff-57/buggy/src.ml @@ -0,0 +1,47 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var v -> if v = x then Const 1 else Var v + | Power (v, p) -> + if v = x then + match p with + | 1 -> Const 1 + | 2 -> Times [ Const p; Var v ] + | _ -> Times [ Const p; Power (v, p - 1) ] + else Power (v, p) + | Times l1 -> + let rec iter (l : aexp list) : aexp list = + match l with + | [] -> [] + | h :: t -> ( + let rec isConst (l : aexp list) : bool = + match l with + | [] -> true + | h :: t -> ( match h with Const c -> isConst t | _ -> false ) + in + if isConst l then [ Const 0 ] + else + match h with + | Const c -> h :: iter t + | Sum lx -> h :: iter t + | _ -> diff (h, x) :: iter t ) + in + Times (iter l1) + | Sum l2 -> + let rec iter (l : aexp list) : aexp list = + match l with + | [] -> [] + | h :: t -> ( + match h with + | Const 0 -> iter t + | Times [ Const 0 ] -> iter t + | _ -> diff (h, x) :: iter t ) + in + Sum (iter l2) diff --git a/OCaml/diff-57/buggy/test.ml b/OCaml/diff-57/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-57/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-57/buggy/testcases b/OCaml/diff-57/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-57/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-57/metadata.json b/OCaml/diff-57/metadata.json new file mode 100644 index 000000000..1ea5c7275 --- /dev/null +++ b/OCaml/diff-57/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-57", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-58/.dockerignore b/OCaml/diff-58/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-58/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-58/Dockerfile b/OCaml/diff-58/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-58/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-58/buggy/src.ml b/OCaml/diff-58/buggy/src.ml new file mode 100644 index 000000000..faede69ef --- /dev/null +++ b/OCaml/diff-58/buggy/src.ml @@ -0,0 +1,26 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) + | Times lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> + Sum + [ Times [ diff (hd, x); mul tl ]; Times [ hd; diff (Times tl, x) ] ] + ) + | Power (v, n) -> Times [ Const n; Power (v, n - 1) ] + | Const n -> Const 0 + | Var y -> if Var y = Var x then Const 1 else Var y + + +and mul (lst : aexp list) : aexp = if lst = [] then Const 1 else Times lst diff --git a/OCaml/diff-58/buggy/test.ml b/OCaml/diff-58/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-58/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-58/buggy/testcases b/OCaml/diff-58/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-58/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-58/metadata.json b/OCaml/diff-58/metadata.json new file mode 100644 index 000000000..483059cf8 --- /dev/null +++ b/OCaml/diff-58/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-58", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-59/.dockerignore b/OCaml/diff-59/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-59/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-59/Dockerfile b/OCaml/diff-59/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-59/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-59/buggy/src.ml b/OCaml/diff-59/buggy/src.ml new file mode 100644 index 000000000..5c0e93470 --- /dev/null +++ b/OCaml/diff-59/buggy/src.ml @@ -0,0 +1,17 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const c -> Const c + | Var v -> ( match v with x -> Times [ Const 0; Var x ] ) + | Power (p, a) -> ( + match (p, a) with x, a -> Times [ Const a; Power (x, a - 1) ] ) + | Times [] -> Const 1 + | Times (hd :: tl) -> Times [ diff (hd, x); diff (Times tl, x) ] + | Sum [] -> Const 0 + | Sum (hd :: tl) -> Sum [ diff (hd, x); diff (Sum tl, x) ] diff --git a/OCaml/diff-59/buggy/test.ml b/OCaml/diff-59/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-59/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-59/buggy/testcases b/OCaml/diff-59/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-59/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-59/metadata.json b/OCaml/diff-59/metadata.json new file mode 100644 index 000000000..366ea8ca4 --- /dev/null +++ b/OCaml/diff-59/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-59", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-6/.dockerignore b/OCaml/diff-6/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-6/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-6/Dockerfile b/OCaml/diff-6/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-6/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-6/buggy/src.ml b/OCaml/diff-6/buggy/src.ml new file mode 100644 index 000000000..26d4b5f5e --- /dev/null +++ b/OCaml/diff-6/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (str : string)) : aexp = + match aexp with + | Const c -> Const 0 + | Var v -> if str = v then Const 1 else Const 0 + | Power (v, p) -> + if v = str then Times [ Const p; Power (v, p - 1) ] else Const 0 + | Times aexpl -> ( + match aexpl with + | [] -> Times [] + | hd :: tl -> + Sum + [ Times (diff (hd, str) :: tl); Times [ hd; diff (Times tl, str) ] ] + ) + | Sum aexpl -> + let diffwithstr (e : aexp) : aexp = diff (e, str) in + Sum (List.map diffwithstr aexpl) diff --git a/OCaml/diff-6/buggy/test.ml b/OCaml/diff-6/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-6/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-6/buggy/testcases b/OCaml/diff-6/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-6/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-6/metadata.json b/OCaml/diff-6/metadata.json new file mode 100644 index 000000000..00fecb5d2 --- /dev/null +++ b/OCaml/diff-6/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-6", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-60/.dockerignore b/OCaml/diff-60/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-60/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-60/Dockerfile b/OCaml/diff-60/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-60/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-60/buggy/src.ml b/OCaml/diff-60/buggy/src.ml new file mode 100644 index 000000000..b56ef604c --- /dev/null +++ b/OCaml/diff-60/buggy/src.ml @@ -0,0 +1,20 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var y -> if x = y then Const 1 else Const 0 + | Power (y, a) -> + if x != y then Const 0 + else if a = 1 then diff (Var y, x) + else Times [ Const a; Power (y, a - 1) ] + | Times (a :: b) -> Times [ a; diff (Sum b, x) ] + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, x); diff (Sum t, x) ] ) diff --git a/OCaml/diff-60/buggy/test.ml b/OCaml/diff-60/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-60/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-60/buggy/testcases b/OCaml/diff-60/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-60/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-60/metadata.json b/OCaml/diff-60/metadata.json new file mode 100644 index 000000000..55cb191c3 --- /dev/null +++ b/OCaml/diff-60/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-60", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-61/.dockerignore b/OCaml/diff-61/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-61/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-61/Dockerfile b/OCaml/diff-61/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-61/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-61/buggy/src.ml b/OCaml/diff-61/buggy/src.ml new file mode 100644 index 000000000..e0a94d7bd --- /dev/null +++ b/OCaml/diff-61/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + let rec diffList (al : aexp list) : aexp list = + match al with + | [] -> [] + | [ e ] -> [ diff (e, x) ] + | hd :: tl -> diff (hd, x) :: diffList tl + in + + match aexp with + | Const c -> Const 0 + | Var v -> Var v + | Power (v, c) -> + if v = x then Times [ Const c; Power (v, c - 1) ] else Const 0 + | Times l -> ( + match l with [] -> Times [] | hd :: tl -> Times (diffList l) ) + | Sum l -> ( match l with [] -> Sum [] | hd :: tl -> Sum (diffList l) ) diff --git a/OCaml/diff-61/buggy/test.ml b/OCaml/diff-61/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-61/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-61/buggy/testcases b/OCaml/diff-61/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-61/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-61/metadata.json b/OCaml/diff-61/metadata.json new file mode 100644 index 000000000..a989d1634 --- /dev/null +++ b/OCaml/diff-61/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-61", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-62/.dockerignore b/OCaml/diff-62/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-62/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-62/Dockerfile b/OCaml/diff-62/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-62/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-62/buggy/src.ml b/OCaml/diff-62/buggy/src.ml new file mode 100644 index 000000000..8450cf0fe --- /dev/null +++ b/OCaml/diff-62/buggy/src.ml @@ -0,0 +1,34 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const c -> Const 0 + | Var a -> if a = x then Const 1 else Const 0 + | Power (a, n) -> Times [ Const n; Power (a, n - 1) ] + | Times l -> Sum (help_times (l, l, 0, x)) + | Sum l -> Sum (help_sum (l, x)) + + +and help_sum ((l : aexp list), (x : string)) : aexp list = + match l with [] -> [] | h :: t -> diff (h, x) :: help_sum (t, x) + + +and help_times1 ((l : aexp list), (n : int), (x : string)) : aexp list = + match l with + | [] -> [] + | h :: t -> + if n = 0 then help_times1 (t, n - 1, x) else h :: help_times1 (t, n - 1, x) + + +and help_times ((ll : aexp list), (l : aexp list), (n : int), (x : string)) : + aexp list = + match l with + | [] -> [] + | h :: t -> + Times (diff (h, x) :: help_times1 (ll, n, x)) + :: help_times (ll, t, n + 1, x) diff --git a/OCaml/diff-62/buggy/test.ml b/OCaml/diff-62/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-62/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-62/buggy/testcases b/OCaml/diff-62/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-62/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-62/metadata.json b/OCaml/diff-62/metadata.json new file mode 100644 index 000000000..49140e7e6 --- /dev/null +++ b/OCaml/diff-62/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-62", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-63/.dockerignore b/OCaml/diff-63/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-63/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-63/Dockerfile b/OCaml/diff-63/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-63/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-63/buggy/src.ml b/OCaml/diff-63/buggy/src.ml new file mode 100644 index 000000000..5b9186f81 --- /dev/null +++ b/OCaml/diff-63/buggy/src.ml @@ -0,0 +1,29 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var k -> if k = x then Const 1 else Var k + | Power (k, i) -> + if k = x then Times [ Const i; Power (k, i - 1) ] else Power (k, i) + | Times l -> ( + match l with + | [] -> Const 0 + | h :: t -> ( + match h with + | Var k -> + if k = x then Times (diff (h, x) :: t) + else Times [ h; diff (Times t, x) ] + | Power (k, i) -> + if k = x then Times (diff (h, x) :: t) + else Times [ h; diff (Times t, x) ] + | _ -> Times [ h; diff (Times t, x) ] ) ) + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, x); diff (Sum t, x) ] ) diff --git a/OCaml/diff-63/buggy/test.ml b/OCaml/diff-63/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-63/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-63/buggy/testcases b/OCaml/diff-63/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-63/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-63/metadata.json b/OCaml/diff-63/metadata.json new file mode 100644 index 000000000..abbeb0227 --- /dev/null +++ b/OCaml/diff-63/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-63", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-64/.dockerignore b/OCaml/diff-64/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-64/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-64/Dockerfile b/OCaml/diff-64/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-64/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-64/buggy/src.ml b/OCaml/diff-64/buggy/src.ml new file mode 100644 index 000000000..bdb65aa20 --- /dev/null +++ b/OCaml/diff-64/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var s -> if s = x then Const 1 else Const 0 + | Power (s, i) -> + if s = x || i != 0 then Times [ Const i; Power (s, i - 1) ] else Const 0 + | Times lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> + Sum + ( [ Times (diff (hd, x) :: tl) ] + @ [ Times [ hd; diff (Times tl, x) ] ] ) ) + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> Sum ([ diff (hd, x) ] @ [ diff (Sum tl, x) ]) ) diff --git a/OCaml/diff-64/buggy/test.ml b/OCaml/diff-64/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-64/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-64/buggy/testcases b/OCaml/diff-64/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-64/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-64/metadata.json b/OCaml/diff-64/metadata.json new file mode 100644 index 000000000..c3e2ef004 --- /dev/null +++ b/OCaml/diff-64/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-64", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-65/.dockerignore b/OCaml/diff-65/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-65/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-65/Dockerfile b/OCaml/diff-65/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-65/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-65/buggy/src.ml b/OCaml/diff-65/buggy/src.ml new file mode 100644 index 000000000..ce12e8de0 --- /dev/null +++ b/OCaml/diff-65/buggy/src.ml @@ -0,0 +1,29 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var b -> if b = x then Const 1 else Var b + | Power (b, a) -> + if b = x then Times [ Const a; Power (x, a - 1) ] else Power (b, a) + | Times l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> ( + match hd with + | Var b -> + if b = x then Times (diff (hd, x) :: tl) + else Times [ hd; diff (Times tl, x) ] + | Power (b, a) -> + if b = x then Times (diff (hd, x) :: tl) + else Times [ hd; diff (Times tl, x) ] + | _ -> Times [ hd; diff (Times tl, x) ] ) ) + | Sum l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) diff --git a/OCaml/diff-65/buggy/test.ml b/OCaml/diff-65/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-65/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-65/buggy/testcases b/OCaml/diff-65/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-65/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-65/metadata.json b/OCaml/diff-65/metadata.json new file mode 100644 index 000000000..e99a89fe1 --- /dev/null +++ b/OCaml/diff-65/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-65", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-66/.dockerignore b/OCaml/diff-66/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-66/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-66/Dockerfile b/OCaml/diff-66/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-66/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-66/buggy/src.ml b/OCaml/diff-66/buggy/src.ml new file mode 100644 index 000000000..accab0579 --- /dev/null +++ b/OCaml/diff-66/buggy/src.ml @@ -0,0 +1,22 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var s -> if s = x then Const 1 else Var s + | Power (s, i) -> + if s = x then Times [ Const i; Power (s, i - 1) ] else Power (s, i) + | Times (hd :: hd' :: tl) -> Times [ hd; diff (hd', x) ] + | Sum li -> + let rec diffForExpList (expList : aexp list) : aexp list = + match expList with + | [] -> raise (Failure "empty list") + | [ one ] -> [ diff (one, x) ] + | hd :: tl -> diff (hd, x) :: diffForExpList tl + in + Sum (diffForExpList li) diff --git a/OCaml/diff-66/buggy/test.ml b/OCaml/diff-66/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-66/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-66/buggy/testcases b/OCaml/diff-66/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-66/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-66/metadata.json b/OCaml/diff-66/metadata.json new file mode 100644 index 000000000..3a92e2524 --- /dev/null +++ b/OCaml/diff-66/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-66", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-67/.dockerignore b/OCaml/diff-67/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-67/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-67/Dockerfile b/OCaml/diff-67/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-67/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-67/buggy/src.ml b/OCaml/diff-67/buggy/src.ml new file mode 100644 index 000000000..916f267bb --- /dev/null +++ b/OCaml/diff-67/buggy/src.ml @@ -0,0 +1,39 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +exception InvalidArgument + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const k -> Const 0 + | Var str -> if str = x then Const 1 else Const 0 + | Power (str, n) -> + if str = x then + if n = 0 then Const 0 + else if n = 1 then Const 0 + else Times [ Const n; Power (str, n - 1) ] + else Const 0 + | Times lst -> ( + if List.mem (Const 0) lst then Const 0 + else + match lst with + | [] -> raise InvalidArgument + | [ hd ] -> diff (hd, x) + | hd :: tl -> ( + match hd with + | Const 1 -> diff (Times tl, x) + | Const k -> Times [ hd; diff (Times tl, x) ] + | _ -> + Sum + [ + Times (diff (hd, x) :: tl); Times [ hd; diff (Times tl, x) ]; + ] ) ) + | Sum lst -> ( + match lst with + | [] -> raise InvalidArgument + | [ hd ] -> diff (hd, x) + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] ) diff --git a/OCaml/diff-67/buggy/test.ml b/OCaml/diff-67/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-67/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-67/buggy/testcases b/OCaml/diff-67/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-67/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-67/metadata.json b/OCaml/diff-67/metadata.json new file mode 100644 index 000000000..e62ff6754 --- /dev/null +++ b/OCaml/diff-67/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-67", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-68/.dockerignore b/OCaml/diff-68/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-68/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-68/Dockerfile b/OCaml/diff-68/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-68/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-68/buggy/src.ml b/OCaml/diff-68/buggy/src.ml new file mode 100644 index 000000000..116dc15cb --- /dev/null +++ b/OCaml/diff-68/buggy/src.ml @@ -0,0 +1,35 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec isvarpow (aexp : aexp) : bool = + match aexp with Var t -> true | Power (x, t) -> true | _ -> false + + +let rec istherevarpow (l : aexp list) : bool = + match l with + | [] -> false + | hd :: tl -> if isvarpow hd then true else istherevarpow tl + + +let aexptolist (aexp : aexp) : aexp list = + match aexp with + | Times (hd :: tl) -> hd :: tl + | Sum (hd :: tl) -> hd :: tl + | _ -> [] + + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const a -> Const 0 + | Var t -> if t = x then Const 1 else Const 0 + | Power (t, n) -> + if t = x then Times [ Const n; Power (t, n - 1) ] else Const 0 + | Times (hd :: tl) -> + Sum + ( Times (diff (hd, x) :: tl) + :: aexptolist (Times (hd :: aexptolist (diff (Times tl, x)))) ) + | Sum (hd :: tl) -> Sum (diff (hd, x) :: aexptolist (diff (Sum tl, x))) diff --git a/OCaml/diff-68/buggy/test.ml b/OCaml/diff-68/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-68/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-68/buggy/testcases b/OCaml/diff-68/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-68/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-68/metadata.json b/OCaml/diff-68/metadata.json new file mode 100644 index 000000000..346dbf266 --- /dev/null +++ b/OCaml/diff-68/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-68", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-69/.dockerignore b/OCaml/diff-69/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-69/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-69/Dockerfile b/OCaml/diff-69/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-69/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-69/buggy/src.ml b/OCaml/diff-69/buggy/src.ml new file mode 100644 index 000000000..f44a5bac4 --- /dev/null +++ b/OCaml/diff-69/buggy/src.ml @@ -0,0 +1,83 @@ +type aexp = + | Const of int + | Var of string + | Power of string * int + | Times of aexp list + | Sum of aexp list + +let rec smrz : aexp -> aexp + = fun aexp -> + match aexp with + Times(l) -> (match l with + [e] -> e + | e::Times(l)::t -> smrz(Times(e::(l@t))) + | Const a::Const b::t -> smrz(Times(Const(a*b)::t)) + | Var(v)::Var(v2)::t -> + if v=v2 + then smrz(Times(Power(v, 2)::t)) + else Times(Var(v)::Var(v2)::t) + | Var(v)::Power(v2, i)::t -> + if v=v2 + then smrz(Times(Power(v, i+1)::t)) + else Times(Var(v)::Power(v2, i)::t) + | Power(v2, i)::Var(v)::t -> + if v=v2 + then smrz(Times(Power(v, i+1)::t)) + else Times(Var(v)::Power(v2, i)::t) + | Power(v, i)::t -> + if i=0 + then smrz(Times(t)) + else if i=1 + then smrz(Times(Var(v)::t)) + else Times(Power(v, i)::t) + | Const a::t -> + if a=0 + then Const 0 + else Times(Const a::t) + | h::t -> Times(smrz(h)::smrz(Times(t))::[]) + | _ -> Times(l) + ) + | Sum(l) -> (match l with + [e] -> e + | Const 0::t -> smrz(Sum(t)) + | e::Sum(l)::t -> smrz(Sum(e::(l@t))) + | Const a::Const b::t -> smrz(Sum(Const(a+b)::t)) + | Var(v)::Var(v2)::t -> + if v=v2 + then smrz(Sum(Const 2::Var(v)::t)) + else Sum(l) + | h::t -> Sum(smrz(h)::smrz(Sum(t))::[]) + | _ -> Sum(l) + ) + | _ -> aexp +;; + +let rec diff : aexp * string -> aexp + = fun (aexp,x) -> + match aexp with + Const(i) -> Const 0 + | Var(v) -> if v=x then Const 1 else Var(v) + | Power(v, i) -> if v=x then + (if i=2 then Times[Const 2; Var(v)] else + if i=1 then Const 1 else Times[Const i; Power(v, i-1)]) + else Power(v, i) + | Times(l) -> let ll = smrz(Times(l)) in + (match ll with + Times(Const a::Var(v)::t) -> + if v=x + then smrz(Times(Const a::t)) + else Times(Const a::Var(v)::t) + | Times(Const a::Power(v, i)::t) -> + if v=x + then smrz(Times(Const(a)::smrz(Times(diff(smrz(Power(v, i)), x)::t))::[])) + else Times(Const a::Power(v, i)::t) + | Times([e]) -> diff(e, x) + | _ -> ll + ) + + | Sum(l) -> let ll = smrz(Sum(l)) in + (match ll with + | Sum([e]) -> smrz(diff(e, x)) + | Sum(h::t) -> smrz(Sum(smrz(diff(h, x))::diff(Sum(t), x)::[])) + | e -> smrz(diff(e, x)) + ) diff --git a/OCaml/diff-69/buggy/test.ml b/OCaml/diff-69/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-69/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-69/buggy/testcases b/OCaml/diff-69/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-69/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-69/metadata.json b/OCaml/diff-69/metadata.json new file mode 100644 index 000000000..2447289e4 --- /dev/null +++ b/OCaml/diff-69/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-69", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-7/.dockerignore b/OCaml/diff-7/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-7/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-7/Dockerfile b/OCaml/diff-7/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-7/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-7/buggy/src.ml b/OCaml/diff-7/buggy/src.ml new file mode 100644 index 000000000..c866ce680 --- /dev/null +++ b/OCaml/diff-7/buggy/src.ml @@ -0,0 +1,31 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((e : aexp), (v : string)) : aexp = + match e with + | Const a -> Const 0 + | Var a -> if a = v then Const 1 else Const 0 + | Power (a, n) -> + if a = v then + if n = 0 then Const 0 else Times [ Const n; Power (a, n - 1) ] + else Const 0 + | Times l -> ( + match l with + | [] -> Const 1 + | h :: t -> + if diff (h, v) = Const 0 then Times [ h; diff (Times t, v) ] + else if diff (h, v) = Const 1 then + Sum [ Times t; Times [ h; diff (Times t, v) ] ] + else + Sum [ Times ([ diff (h, v) ] @ t); Times [ h; diff (Times t, v) ] ] + ) + | Sum l -> ( + match l with + | [] -> Const 0 + | h :: t -> + if diff (h, v) = Const 0 then diff (Sum t, v) + else Sum [ diff (h, v); diff (Sum t, v) ] ) diff --git a/OCaml/diff-7/buggy/test.ml b/OCaml/diff-7/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-7/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-7/buggy/testcases b/OCaml/diff-7/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-7/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-7/metadata.json b/OCaml/diff-7/metadata.json new file mode 100644 index 000000000..b89ff2046 --- /dev/null +++ b/OCaml/diff-7/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-7", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-70/.dockerignore b/OCaml/diff-70/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-70/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-70/Dockerfile b/OCaml/diff-70/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-70/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-70/buggy/src.ml b/OCaml/diff-70/buggy/src.ml new file mode 100644 index 000000000..7328940ad --- /dev/null +++ b/OCaml/diff-70/buggy/src.ml @@ -0,0 +1,8 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = aexp diff --git a/OCaml/diff-70/buggy/test.ml b/OCaml/diff-70/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-70/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-70/buggy/testcases b/OCaml/diff-70/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-70/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-70/metadata.json b/OCaml/diff-70/metadata.json new file mode 100644 index 000000000..ab4f09b94 --- /dev/null +++ b/OCaml/diff-70/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-70", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-71/.dockerignore b/OCaml/diff-71/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-71/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-71/Dockerfile b/OCaml/diff-71/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-71/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-71/buggy/src.ml b/OCaml/diff-71/buggy/src.ml new file mode 100644 index 000000000..455d55598 --- /dev/null +++ b/OCaml/diff-71/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const int1 -> Const 0 + | Var x -> Const 1 + | Power (var, int1) -> Times [ Const int1; Power (var, int1 - 1) ] + | Times lst -> ( + match lst with + | [] -> Const 1 + | hd :: tail -> + if diff (hd, x) = Const 0 then Times [ hd; diff (Times tail, x) ] + else if diff (hd, x) = Const 1 then Times (Const 1 :: Const 1 :: tail) + else Times (Const 1 :: diff (hd, x) :: tail) ) + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tail -> Sum [ diff (hd, x); diff (Sum tail, x) ] ) diff --git a/OCaml/diff-71/buggy/test.ml b/OCaml/diff-71/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-71/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-71/buggy/testcases b/OCaml/diff-71/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-71/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-71/metadata.json b/OCaml/diff-71/metadata.json new file mode 100644 index 000000000..6a0dfd27c --- /dev/null +++ b/OCaml/diff-71/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-71", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-72/.dockerignore b/OCaml/diff-72/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-72/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-72/Dockerfile b/OCaml/diff-72/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-72/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-72/buggy/src.ml b/OCaml/diff-72/buggy/src.ml new file mode 100644 index 000000000..d41352a5f --- /dev/null +++ b/OCaml/diff-72/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const y -> Const 0 + | Var t -> if t = x then Const 1 else Const 0 + | Power (s, i) -> Times [ Const i; Power (s, i - 1) ] + | Times k -> ( + match k with + | [] -> Const 0 + | hd :: tl -> + Sum + ( [ Times ([ diff (hd, x) ] @ tl) ] + @ [ Times ([ hd ] @ [ diff (Times tl, x) ]) ] ) ) + | Sum k -> ( + match k with + | [] -> Const 0 + | h :: t -> Sum ([ diff (h, x) ] @ [ Sum [ diff (Sum t, x) ] ]) ) diff --git a/OCaml/diff-72/buggy/test.ml b/OCaml/diff-72/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-72/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-72/buggy/testcases b/OCaml/diff-72/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-72/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-72/metadata.json b/OCaml/diff-72/metadata.json new file mode 100644 index 000000000..6ac165e64 --- /dev/null +++ b/OCaml/diff-72/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-72", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-73/.dockerignore b/OCaml/diff-73/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-73/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-73/Dockerfile b/OCaml/diff-73/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-73/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-73/buggy/src.ml b/OCaml/diff-73/buggy/src.ml new file mode 100644 index 000000000..db574a67b --- /dev/null +++ b/OCaml/diff-73/buggy/src.ml @@ -0,0 +1,15 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Const i -> Const 0 + | Var a -> if a = "x" then Const 1 else Const 0 + | Power (a, i) -> Times [ Const i; Power (a, i - 1) ] + | Times (h :: t) -> Times [ h; diff (Sum t, x) ] + | Sum (h :: t) -> Sum [ diff (h, x); diff (Sum t, x) ] + | _ -> Const 0 diff --git a/OCaml/diff-73/buggy/test.ml b/OCaml/diff-73/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-73/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-73/buggy/testcases b/OCaml/diff-73/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-73/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-73/metadata.json b/OCaml/diff-73/metadata.json new file mode 100644 index 000000000..fab181d94 --- /dev/null +++ b/OCaml/diff-73/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-73", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-74/.dockerignore b/OCaml/diff-74/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-74/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-74/Dockerfile b/OCaml/diff-74/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-74/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-74/buggy/src.ml b/OCaml/diff-74/buggy/src.ml new file mode 100644 index 000000000..7328940ad --- /dev/null +++ b/OCaml/diff-74/buggy/src.ml @@ -0,0 +1,8 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = aexp diff --git a/OCaml/diff-74/buggy/test.ml b/OCaml/diff-74/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-74/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-74/buggy/testcases b/OCaml/diff-74/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-74/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-74/metadata.json b/OCaml/diff-74/metadata.json new file mode 100644 index 000000000..cb292110d --- /dev/null +++ b/OCaml/diff-74/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-74", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-75/.dockerignore b/OCaml/diff-75/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-75/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-75/Dockerfile b/OCaml/diff-75/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-75/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-75/buggy/src.ml b/OCaml/diff-75/buggy/src.ml new file mode 100644 index 000000000..0b2429864 --- /dev/null +++ b/OCaml/diff-75/buggy/src.ml @@ -0,0 +1,17 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Var x -> Const 1 + | Power (x, n) -> Times [ Const n; Power (x, n - 1) ] + | Times [ a; b ] -> Times [ a; diff (b, x) ] + | Sum l -> ( + match l with + | hd :: tl -> Sum [ diff (hd, x); diff (Sum tl, x) ] + | [] -> Const 0 ) + | _ -> Const 0 diff --git a/OCaml/diff-75/buggy/test.ml b/OCaml/diff-75/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-75/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-75/buggy/testcases b/OCaml/diff-75/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-75/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-75/metadata.json b/OCaml/diff-75/metadata.json new file mode 100644 index 000000000..d9aacf7c7 --- /dev/null +++ b/OCaml/diff-75/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-75", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-76/.dockerignore b/OCaml/diff-76/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-76/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-76/Dockerfile b/OCaml/diff-76/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-76/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-76/buggy/src.ml b/OCaml/diff-76/buggy/src.ml new file mode 100644 index 000000000..34a18ceb0 --- /dev/null +++ b/OCaml/diff-76/buggy/src.ml @@ -0,0 +1,59 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec check_times ((li : aexp list), (str : string)) : int = + match li with + | [] -> 0 + | h :: t -> ( + match h with + | Var str3 -> if str = str3 then 1 else check_times (t, str) + | Power (str2, a) -> if str = str2 then 2 else check_times (t, str) + | _ -> check_times (t, str) ) + + +let rec align_head ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Times (h :: t) -> + if h = Var x then Times (h :: t) else align_head (Times (t @ [ h ]), x) + | _ -> raise (Failure "HowDidYouGetHere") + + +let work_head ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Times (h :: t) -> Times t + | _ -> raise (Failure "HowDidYouGetHere") + + +let rec align_head_power ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Times (h :: t) -> ( + match h with + | Power (x, _) -> Times (h :: t) + | _ -> align_head_power (Times (t @ [ h ]), x) ) + | _ -> raise (Failure "HowDidYouGetHere") + + +let rec diff ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Sum (h :: t) -> Sum [ diff (h, x); diff (Sum t, x) ] + | Times li -> ( + match check_times (li, x) with + | 0 -> Const 0 + | 1 -> work_head (align_head (Times li, x), x) + | 2 -> work_head_power (align_head_power (Times li, x), x) + | _ -> Const 0 ) + | Sum [] -> Const 0 + | Const a -> Const 0 + | Var str -> if str = x then Const 1 else Const 0 + | Power (str, a) -> + if str = x then Times [ Const a; Power (str, a - 1) ] else Const 0 + + +and work_head_power ((aexp : aexp), (x : string)) : aexp = + match aexp with + | Times (h :: t) -> Times ([ diff (h, x) ] @ t) + | _ -> raise (Failure "HowDidYouGetHere") diff --git a/OCaml/diff-76/buggy/test.ml b/OCaml/diff-76/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-76/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-76/buggy/testcases b/OCaml/diff-76/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-76/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-76/metadata.json b/OCaml/diff-76/metadata.json new file mode 100644 index 000000000..3ebcf2eed --- /dev/null +++ b/OCaml/diff-76/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-76", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-77/.dockerignore b/OCaml/diff-77/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-77/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-77/Dockerfile b/OCaml/diff-77/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-77/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-77/buggy/src.ml b/OCaml/diff-77/buggy/src.ml new file mode 100644 index 000000000..a1ee2c12f --- /dev/null +++ b/OCaml/diff-77/buggy/src.ml @@ -0,0 +1,28 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const i -> Const 0 + | Var s -> if s = var then Const 1 else Var s + | Power (s, i) -> + if s = var then Times [ Const i; Power (s, i - 1) ] else Power (s, i) + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) + | Times lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> + if diff (hd, var) = Const 0 then Times [ hd; diff (Times tl, var) ] + else + Sum + [ + Times ([ diff (hd, var) ] @ tl); + Times [ hd; diff (Times tl, var) ]; + ] ) diff --git a/OCaml/diff-77/buggy/test.ml b/OCaml/diff-77/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-77/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-77/buggy/testcases b/OCaml/diff-77/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-77/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-77/metadata.json b/OCaml/diff-77/metadata.json new file mode 100644 index 000000000..4d70e95c2 --- /dev/null +++ b/OCaml/diff-77/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-77", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-78/.dockerignore b/OCaml/diff-78/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-78/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-78/Dockerfile b/OCaml/diff-78/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-78/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-78/buggy/src.ml b/OCaml/diff-78/buggy/src.ml new file mode 100644 index 000000000..a71a3107a --- /dev/null +++ b/OCaml/diff-78/buggy/src.ml @@ -0,0 +1,34 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match (exp, var) with + | Const n, v -> Const 0 + | Var x, v -> if x = v then Const 1 else Const 0 + | Power (v1, n), v -> + if v1 = v then Times [ Const n; Power (v1, n - 1) ] else Const 0 + | Times l, v -> ( + match l with + | Const n :: tl -> Times (Const (n * iter v l) :: tl) + | _ -> Const 0 ) + | Sum l, v -> ( + match l with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, v); diff (Sum tl, v) ] ) + + +and count (x : string) (e : aexp) : int = + match e with + | Const n -> 0 + | Var v -> if x = v then 1 else 0 + | Power (v, n) -> if v = x then n else 0 + | Times l -> iter x l + | Sum l -> 0 + + +and iter (x : string) (l : aexp list) : int = + match l with [] -> 0 | hd :: tl -> count x hd + iter x tl diff --git a/OCaml/diff-78/buggy/test.ml b/OCaml/diff-78/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-78/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-78/buggy/testcases b/OCaml/diff-78/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-78/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-78/metadata.json b/OCaml/diff-78/metadata.json new file mode 100644 index 000000000..b1306658c --- /dev/null +++ b/OCaml/diff-78/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-78", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-79/.dockerignore b/OCaml/diff-79/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-79/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-79/Dockerfile b/OCaml/diff-79/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-79/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-79/buggy/src.ml b/OCaml/diff-79/buggy/src.ml new file mode 100644 index 000000000..02481c000 --- /dev/null +++ b/OCaml/diff-79/buggy/src.ml @@ -0,0 +1,33 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const a -> Const 0 + | Var s -> if s = var then Const 1 else Const 0 + | Power (s, a) -> + if a = 1 then Const 1 else Times [ Const a; Power (s, a - 1) ] + | Times lst -> ( + match lst with + | [] -> Const 0 + | h :: t -> + if t = [] then + Sum + [ + Times [ diff (h, var); Const 1 ]; + Times [ h; diff (Times t, var) ]; + ] + else + Sum + [ + Times [ diff (h, var); Times t ]; + Times [ h; diff (Times t, var) ]; + ] ) + | Sum lst2 -> ( + match lst2 with + | [] -> Const 0 + | h :: t -> Sum [ diff (h, var); diff (Sum t, var) ] ) diff --git a/OCaml/diff-79/buggy/test.ml b/OCaml/diff-79/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-79/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-79/buggy/testcases b/OCaml/diff-79/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-79/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-79/metadata.json b/OCaml/diff-79/metadata.json new file mode 100644 index 000000000..65c664452 --- /dev/null +++ b/OCaml/diff-79/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-79", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-8/.dockerignore b/OCaml/diff-8/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-8/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-8/Dockerfile b/OCaml/diff-8/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-8/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-8/buggy/src.ml b/OCaml/diff-8/buggy/src.ml new file mode 100644 index 000000000..ad95750b3 --- /dev/null +++ b/OCaml/diff-8/buggy/src.ml @@ -0,0 +1,43 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((alexp : aexp), (str : string)) : aexp = + let zeroTimes (a : aexp) : aexp = + match a with + | Times (hd :: tl) -> + if hd = Const 0 || List.mem (Const 0) tl then Const 0 else a + | _ -> a + in + + match alexp with + | Const c -> Const 0 + | Var s -> if s != str then Const 0 else Const 1 + | Power (s, n) -> + if s != str then Const 0 + else if n = 0 then Const 1 + else if n = 1 then Const n + else if n = 2 then Times [ Const n; Var s ] + else Times [ Const n; Power (s, n - 1) ] + | Times (hd :: tl) -> + if tl = [] then diff (hd, str) + else + let ht : aexp = zeroTimes (Times (diff (hd, str) :: tl)) in + + let st : aexp = zeroTimes (Times [ hd; diff (Times tl, str) ]) in + if ht = Const 0 && st = Const 0 then Const 0 + else if ht = Const 0 then st + else if st = Const 0 then ht + else Sum [ ht; st ] + | Times [] -> Const 0 + | Sum (hd :: tl) -> + if tl = [] then diff (hd, str) + else + let h : aexp = diff (hd, str) in + + let t : aexp = diff (Sum tl, str) in + if h = Const 0 then t else if t = Const 0 then h else Sum [ h; t ] + | Sum [] -> Const 0 diff --git a/OCaml/diff-8/buggy/test.ml b/OCaml/diff-8/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-8/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-8/buggy/testcases b/OCaml/diff-8/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-8/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-8/metadata.json b/OCaml/diff-8/metadata.json new file mode 100644 index 000000000..ff5ee032d --- /dev/null +++ b/OCaml/diff-8/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-8", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-80/.dockerignore b/OCaml/diff-80/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-80/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-80/Dockerfile b/OCaml/diff-80/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-80/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-80/buggy/src.ml b/OCaml/diff-80/buggy/src.ml new file mode 100644 index 000000000..aa964bf73 --- /dev/null +++ b/OCaml/diff-80/buggy/src.ml @@ -0,0 +1,18 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const c -> Const 0 + | Var v -> if v = var then Const 1 else Const 0 + | Power (st, i) -> + if st = var then Times [ Const i; Power (st, i - 1) ] else Power (st, i) + | Times (h :: t) -> h + | Sum (h :: t) -> + let diffHelp (alexp : aexp) : aexp = diff (alexp, var) in + Sum (diff (h, var) :: List.map diffHelp t) + | _ -> exp diff --git a/OCaml/diff-80/buggy/test.ml b/OCaml/diff-80/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-80/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-80/buggy/testcases b/OCaml/diff-80/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-80/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-80/metadata.json b/OCaml/diff-80/metadata.json new file mode 100644 index 000000000..53708ec6f --- /dev/null +++ b/OCaml/diff-80/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-80", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-81/.dockerignore b/OCaml/diff-81/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-81/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-81/Dockerfile b/OCaml/diff-81/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-81/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-81/buggy/src.ml b/OCaml/diff-81/buggy/src.ml new file mode 100644 index 000000000..973761cac --- /dev/null +++ b/OCaml/diff-81/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec p1_help ((aexp : aexp list), (var : string)) : aexp list = + match aexp with [] -> [] | hd :: tl -> diff (hd, var) :: p1_help (tl, var) + + +and diff ((aexp : aexp), (var : string)) : aexp = + match aexp with + | Const n -> Const 0 + | Var y -> if y = var then Const 1 else Const 0 + | Power (y, n) -> + if y = var then Times [ Const n; Power (y, n - 1) ] else Const 0 + | Times aexp1 -> ( + match aexp1 with + | [] -> Const 0 + | hd :: tl -> + Sum [ Times (diff (hd, var) :: tl); Times (hd :: p1_help (tl, var)) ] + ) + | Sum aexp1 -> Sum (p1_help (aexp1, var)) diff --git a/OCaml/diff-81/buggy/test.ml b/OCaml/diff-81/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-81/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-81/buggy/testcases b/OCaml/diff-81/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-81/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-81/metadata.json b/OCaml/diff-81/metadata.json new file mode 100644 index 000000000..5146af170 --- /dev/null +++ b/OCaml/diff-81/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-81", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-82/.dockerignore b/OCaml/diff-82/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-82/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-82/Dockerfile b/OCaml/diff-82/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-82/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-82/buggy/src.ml b/OCaml/diff-82/buggy/src.ml new file mode 100644 index 000000000..38fb9b5d5 --- /dev/null +++ b/OCaml/diff-82/buggy/src.ml @@ -0,0 +1,37 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const a -> Const 0 + | Var v -> if v = var then Const 1 else Var v + | Power (v, a) -> + if v = var then + match a with + | 2 -> Times [ Const 2; Var v ] + | 1 -> Const 1 + | 0 -> Const 0 + | _ -> Times [ Const a; Power (v, a - 1) ] + else Power (v, a) + | Times l -> ( + match l with + | h :: t -> + if t = [] then diff (h, var) + else + Sum [ Times (diff (h, var) :: t); Times [ h; diff (Times t, var) ] ] + ) + | Sum l -> + let rec subsum (l : aexp list) : aexp list = + match l with + | [] -> [] + | h :: t -> ( + match h with + | Const 0 -> subsum t + | Times [ Const 0 ] -> subsum t + | _ -> diff (h, var) :: subsum t ) + in + Sum (subsum l) diff --git a/OCaml/diff-82/buggy/test.ml b/OCaml/diff-82/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-82/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-82/buggy/testcases b/OCaml/diff-82/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-82/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-82/metadata.json b/OCaml/diff-82/metadata.json new file mode 100644 index 000000000..4d061bdcd --- /dev/null +++ b/OCaml/diff-82/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-82", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-83/.dockerignore b/OCaml/diff-83/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-83/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-83/Dockerfile b/OCaml/diff-83/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-83/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-83/buggy/src.ml b/OCaml/diff-83/buggy/src.ml new file mode 100644 index 000000000..86183c588 --- /dev/null +++ b/OCaml/diff-83/buggy/src.ml @@ -0,0 +1,80 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec processtimelist ((l : aexp), (var : string)) : aexp = + match l with + | Const i -> Const i + | Var str -> if str = var then Const 0 else Var str + | Power (str, i) -> + if str = var then + match i with + | 2 -> Times [ Const 2; Var str ] + | 1 -> Const 1 + | 0 -> Const 0 + | _ -> Times [ Const i; Power (str, i - 1) ] + else Power (str, i) + | Times (hd :: tl) -> + if findlist (hd :: tl, var) > 0 then + Sum + ( [ Times (processtimelist (hd, var) :: tl) ] + @ [ Times ([ hd ] @ [ processtimelist (Times tl, var) ]) ] ) + else Const 1 + | _ -> makediff (l, var) + + +and processsumlist ((l : aexp list), (var : string)) : aexp list = + match l with + | [] -> [] + | hd :: tl -> ( + match hd with + | Var str -> + if str = var then Const 1 :: processsumlist (tl, var) + else Const 0 :: processsumlist (tl, var) + | _ -> makediff (hd, var) :: processsumlist (tl, var) ) + + +and findlist ((l : aexp list), (str : string)) : int = + match l with + | [] -> 0 + | hd :: tl -> ( + match hd with + | Const i -> findlist (tl, str) + | Var str2 -> + if str = str2 then 1 + findlist (tl, str) else findlist (tl, str) + | Power (str2, i) -> + if str = str2 then i + findlist (tl, str) else findlist (tl, str) + | Times l -> findlist (l, str) + findlist (tl, str) + | Sum l -> findlist (l, str) + findlist (tl, str) ) + + +and makediff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const i -> Const 0 + | Var str -> if str = var then Const 1 else Const 0 + | Power (str, i) -> + if str = var then + match i with + | 2 -> Times [ Const 2; Var str ] + | 1 -> Const 1 + | 0 -> Const 0 + | _ -> Times [ Const i; Power (str, i - 1) ] + else Const 0 + | Times (hd :: tl) -> + if findlist (hd :: tl, var) > 0 then + Sum + ( [ Times (processtimelist (hd, var) :: tl) ] + @ [ Times ([ hd ] @ [ processtimelist (Times tl, var) ]) ] ) + else Const 1 + | Times [] -> Const 0 + | Sum (hd :: tl) -> + if findlist (hd :: tl, var) > 0 then + Sum ([ makediff (hd, var) ] @ [ makediff (Sum tl, var) ]) + else Const 1 + | Sum [] -> Const 1 + + +let rec diff ((exp : aexp), (var : string)) : aexp = makediff (exp, var) diff --git a/OCaml/diff-83/buggy/test.ml b/OCaml/diff-83/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-83/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-83/buggy/testcases b/OCaml/diff-83/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-83/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-83/metadata.json b/OCaml/diff-83/metadata.json new file mode 100644 index 000000000..424300ab5 --- /dev/null +++ b/OCaml/diff-83/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-83", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-84/.dockerignore b/OCaml/diff-84/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-84/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-84/Dockerfile b/OCaml/diff-84/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-84/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-84/buggy/src.ml b/OCaml/diff-84/buggy/src.ml new file mode 100644 index 000000000..b793a1063 --- /dev/null +++ b/OCaml/diff-84/buggy/src.ml @@ -0,0 +1,31 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const i -> Const 0 + | Var s -> if s = var then Const 1 else Const 0 + | Power (s, i) -> + if s = var then Times [ Const i; Power (s, i - 1) ] else Const 0 + | Times lst -> ( + match lst with + | [] -> Const 1 + | hd :: tl -> Times [ diff_times_helper (hd, var); diff (Times tl, var) ] + ) + | Sum lst -> ( + match lst with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) + + +and diff_times_helper ((exp : aexp), (var : string)) : aexp = + match exp with + | Const i -> Const i + | Var s -> if s = var then Const 1 else Var s + | Power (s, i) -> + if s = var then Times [ Const i; Power (s, i - 1) ] else Power (s, i) + | _ -> diff (exp, var) diff --git a/OCaml/diff-84/buggy/test.ml b/OCaml/diff-84/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-84/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-84/buggy/testcases b/OCaml/diff-84/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-84/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-84/metadata.json b/OCaml/diff-84/metadata.json new file mode 100644 index 000000000..7376d204e --- /dev/null +++ b/OCaml/diff-84/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-84", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-85/.dockerignore b/OCaml/diff-85/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-85/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-85/Dockerfile b/OCaml/diff-85/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-85/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-85/buggy/src.ml b/OCaml/diff-85/buggy/src.ml new file mode 100644 index 000000000..a9af3932b --- /dev/null +++ b/OCaml/diff-85/buggy/src.ml @@ -0,0 +1,54 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec contain ((exp : aexp list), (var : string)) : bool = + match (exp, var) with + | [], x -> false + | Const a :: tl, x -> contain (tl, x) + | Var a :: tl, x -> if a = x then true else contain (tl, x) + | Power (x, a) :: tl, y -> if x = y && a != 0 then true else contain (tl, x) + | _, _ -> raise (Failure "Invalid input") + + +let rec timesHelper ((exp : aexp list), (var : string)) : aexp list = + match (exp, var) with + | [], x -> [] + | Const a :: tl, x -> Const a :: timesHelper (tl, x) + | Var a :: tl, x -> + if a = x then Const 1 :: timesHelper (tl, x) + else Var a :: timesHelper (tl, x) + | Power (x, a) :: tl, y -> + if x = y && a != 0 then + Times [ Const a; Power (x, a - 1) ] :: timesHelper (tl, y) + else Power (x, a) :: timesHelper (tl, y) + | _, _ -> raise (Failure "Invalid input") + + +let rec sumHelper ((exp : aexp list), (var : string)) : aexp list = + match (exp, var) with + | [], x -> [] + | Const a :: tl, x -> Const 0 :: sumHelper (tl, x) + | Var a :: tl, x -> + if a = x then Const 1 :: sumHelper (tl, x) else sumHelper (tl, x) + | Power (x, a) :: tl, y -> + if x = y && a != 0 then + Times [ Const a; Power (x, a - 1) ] :: sumHelper (tl, y) + else Const 0 :: sumHelper (tl, y) + | Times t :: tl, x -> + if contain (t, x) then Times (timesHelper (t, x)) :: sumHelper (tl, x) + else Const 0 :: sumHelper (tl, x) + | _, _ -> raise (Failure "Invalid input") + + +let rec diff ((exp : aexp), (var : string)) : aexp = + match (exp, var) with + | Const a, x -> Const 0 + | Var a, x -> if a = x then Const 1 else Const 0 + | Power (x, a), y -> + if x = y && a != 0 then Times [ Const a; Power (x, a - 1) ] else Const 0 + | Times t, x -> if contain (t, x) then Times (timesHelper (t, x)) else Const 0 + | Sum s, x -> Sum (sumHelper (s, x)) diff --git a/OCaml/diff-85/buggy/test.ml b/OCaml/diff-85/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-85/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-85/buggy/testcases b/OCaml/diff-85/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-85/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-85/metadata.json b/OCaml/diff-85/metadata.json new file mode 100644 index 000000000..2e347ae27 --- /dev/null +++ b/OCaml/diff-85/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-85", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-86/.dockerignore b/OCaml/diff-86/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-86/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-86/Dockerfile b/OCaml/diff-86/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-86/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-86/buggy/src.ml b/OCaml/diff-86/buggy/src.ml new file mode 100644 index 000000000..d41386e78 --- /dev/null +++ b/OCaml/diff-86/buggy/src.ml @@ -0,0 +1,19 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const x -> Const 0 + | Var x -> if x = var then Const 1 else Const 0 + | Power (x, y) -> + if x = var then Times [ Const y; Power (x, y - 1) ] else Const 0 + | Times x -> Const 0 + | Sum x -> + let rec diff1 (l : aexp list) : aexp list = + match l with [] -> [] | hd :: tl -> diff (hd, var) :: diff1 tl + in + Sum (diff1 x) diff --git a/OCaml/diff-86/buggy/test.ml b/OCaml/diff-86/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-86/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-86/buggy/testcases b/OCaml/diff-86/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-86/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-86/metadata.json b/OCaml/diff-86/metadata.json new file mode 100644 index 000000000..ade034b52 --- /dev/null +++ b/OCaml/diff-86/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-86", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-87/.dockerignore b/OCaml/diff-87/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-87/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-87/Dockerfile b/OCaml/diff-87/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-87/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-87/buggy/src.ml b/OCaml/diff-87/buggy/src.ml new file mode 100644 index 000000000..1a6abcf2b --- /dev/null +++ b/OCaml/diff-87/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const n -> Const 0 + | Var x -> if x = var then Const 1 else exp + | Power (x, n) -> if x = var then Times [ Const n; Power (x, n - 1) ] else exp + | Times l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> + Sum + ( [ Times (diff (hd, var) :: tl) ] + @ [ Times [ hd; diff (Times tl, var) ] ] ) ) + | Sum l -> ( + match l with + | [] -> Const 0 + | hd :: tl -> Sum ([ diff (hd, var) ] @ [ diff (Sum tl, var) ]) ) diff --git a/OCaml/diff-87/buggy/test.ml b/OCaml/diff-87/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-87/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-87/buggy/testcases b/OCaml/diff-87/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-87/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-87/metadata.json b/OCaml/diff-87/metadata.json new file mode 100644 index 000000000..2857c7ea0 --- /dev/null +++ b/OCaml/diff-87/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-87", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-88/.dockerignore b/OCaml/diff-88/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-88/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-88/Dockerfile b/OCaml/diff-88/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-88/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-88/buggy/src.ml b/OCaml/diff-88/buggy/src.ml new file mode 100644 index 000000000..625ba2eb3 --- /dev/null +++ b/OCaml/diff-88/buggy/src.ml @@ -0,0 +1,50 @@ +type aexp = + | Const of int + | Var of string + | Power of string * int + | Times of aexp list + | Sum of aexp list + +let diff : aexp * string -> aexp = + fun (exp, var) -> + let rec f e v = + match e with + | Const a -> Const 0 + | Var a -> if a = var then Const 1 else Const 0 + | Power (x, y) -> + if x = var then Times [ Const y; Power (x, y - 1) ] else Const 0 + | Sum lst -> ( + match lst with + | [] -> raise (Failure " No elements in the list! ") + | hd :: tl -> + if tl == [] then f hd var + else Sum ([ f hd var ] @ [ f (Sum tl) var ]) ) + | Times lst -> ( + match lst with + | [] -> raise (Failure " No elements in the list! ") + | hd :: tl -> ( + if tl == [] then f hd var + else + match hd with + | Const a -> Times ([ hd ] @ [ f (Times tl) var ]) + | Var a -> + if hd = Var var then + Sum ([ f (Times tl) var ] @ [ hd ] @ [ f (Times tl) var ]) + else Times ([ hd ] @ [ f (Times tl) var ]) + | Power (x, y) -> + if Var x = Var var then + Sum + ( [ Times ([ f hd var ] @ tl) ] + @ [ Times ([ hd ] @ [ f (Times tl) var ]) ] ) + else Times ([ hd ] @ [ f (Times tl) var ]) + | Sum ist -> + Sum + ( [ Times ([ f hd var ] @ tl) ] + @ [ Times ([ hd ] @ [ f (Times tl) var ]) ] ) + | Times ist -> + Sum + ( [ Times ([ f hd var ] @ tl) ] + @ [ Times ([ hd ] @ [ f (Times tl) var ]) ] ) ) ) + in + + f exp var diff --git a/OCaml/diff-88/buggy/test.ml b/OCaml/diff-88/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-88/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-88/buggy/testcases b/OCaml/diff-88/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-88/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-88/metadata.json b/OCaml/diff-88/metadata.json new file mode 100644 index 000000000..c281ced18 --- /dev/null +++ b/OCaml/diff-88/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-88", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-89/.dockerignore b/OCaml/diff-89/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-89/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-89/Dockerfile b/OCaml/diff-89/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-89/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-89/buggy/src.ml b/OCaml/diff-89/buggy/src.ml new file mode 100644 index 000000000..5cf2403e9 --- /dev/null +++ b/OCaml/diff-89/buggy/src.ml @@ -0,0 +1,38 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const c -> Const 0 + | Var x -> if x = var then Const 1 else Const 0 + | Power (x, n) -> + if x = var then + if n > 2 || n < 0 then Power (x, n - 1) + else if n = 2 then Times [ Const 2; Var x ] + else if n = 1 then Const 1 + else Const 0 + else Const 0 + | Times lexp -> ( + match lexp with + | [] -> Const 1 + | [ hd ] -> diff (hd, var) + | hd :: tl -> ( + match hd with + | Const 0 -> Const 0 + | Const 1 -> diff (Times tl, var) + | Const c -> Times [ Const c; diff (Times tl, var) ] + | _ -> + Sum + [ + Times (diff (hd, var) :: tl); + Times [ hd; diff (Times tl, var) ]; + ] ) ) + | Sum lexp -> ( + match lexp with + | [] -> Const 0 + | [ hd ] -> diff (hd, var) + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) diff --git a/OCaml/diff-89/buggy/test.ml b/OCaml/diff-89/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-89/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-89/buggy/testcases b/OCaml/diff-89/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-89/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-89/metadata.json b/OCaml/diff-89/metadata.json new file mode 100644 index 000000000..ffa6b15b0 --- /dev/null +++ b/OCaml/diff-89/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-89", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-9/.dockerignore b/OCaml/diff-9/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-9/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-9/Dockerfile b/OCaml/diff-9/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-9/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-9/buggy/src.ml b/OCaml/diff-9/buggy/src.ml new file mode 100644 index 000000000..dac9d4718 --- /dev/null +++ b/OCaml/diff-9/buggy/src.ml @@ -0,0 +1,23 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (var : string)) : aexp = + match aexp with + | Const x -> Const 0 + | Var x -> Const 1 + | Power (x, i) -> + if i = 0 then Const 0 + else if i = 1 then Const 1 + else Times [ Const i; Power (x, i - 1) ] + | Times aexplist -> ( + match aexplist with + | [] -> Const 0 + | hd :: tl -> + Sum + [ Times (diff (hd, var) :: tl); Times [ hd; diff (Times tl, var) ] ] + ) + | Sum aexplist -> Sum (List.map (fun (x : aexp) -> diff (x, var)) aexplist) diff --git a/OCaml/diff-9/buggy/test.ml b/OCaml/diff-9/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-9/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-9/buggy/testcases b/OCaml/diff-9/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-9/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-9/metadata.json b/OCaml/diff-9/metadata.json new file mode 100644 index 000000000..790744c6a --- /dev/null +++ b/OCaml/diff-9/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-9", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-90/.dockerignore b/OCaml/diff-90/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-90/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-90/Dockerfile b/OCaml/diff-90/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-90/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-90/buggy/src.ml b/OCaml/diff-90/buggy/src.ml new file mode 100644 index 000000000..d56f39c11 --- /dev/null +++ b/OCaml/diff-90/buggy/src.ml @@ -0,0 +1,31 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((aexp : aexp), (var : string)) : aexp = + match aexp with + | Const cst1 -> Const 0 + | Var var1 -> if var1 = var then Const 1 else Const 0 + | Power (str, int1) -> ( + match int1 with + | 0 -> Const 0 + | 1 -> if str = var then Const 1 else Const 0 + | _ -> Times [ Power (str, int1 - 1); Const int1 ] ) + | Sum sum_lst -> ( + match sum_lst with + | [] -> Const 0 + | [ hd ] -> diff (hd, var) + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) + | Times tm_lst -> ( + match tm_lst with + | [] -> Const 1 + | [ hd ] -> diff (hd, var) + | hd :: tl -> + Sum + [ + Times [ diff (hd, var); Times tl ]; + Times [ hd; diff (Times tl, var) ]; + ] ) diff --git a/OCaml/diff-90/buggy/test.ml b/OCaml/diff-90/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-90/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-90/buggy/testcases b/OCaml/diff-90/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-90/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-90/metadata.json b/OCaml/diff-90/metadata.json new file mode 100644 index 000000000..f3619a535 --- /dev/null +++ b/OCaml/diff-90/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-90", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-91/.dockerignore b/OCaml/diff-91/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-91/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-91/Dockerfile b/OCaml/diff-91/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-91/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-91/buggy/src.ml b/OCaml/diff-91/buggy/src.ml new file mode 100644 index 000000000..1a4ee2a26 --- /dev/null +++ b/OCaml/diff-91/buggy/src.ml @@ -0,0 +1,26 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const a -> Const 0 + | Var x -> if x = var then Const 1 else Var x + | Power (x, set) -> + if x = var then Times [ Const set; Power (x, set - 1) ] else Power (x, set) + | Times l -> ( + match l with + | [] -> Const 1 + | [ e ] -> diff (e, var) + | hd :: tl -> + Sum + [ Times (diff (hd, var) :: tl); Times [ hd; diff (Times tl, var) ] ] + ) + | Sum l -> ( + match l with + | [] -> Const 0 + | [ e ] -> diff (e, var) + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) diff --git a/OCaml/diff-91/buggy/test.ml b/OCaml/diff-91/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-91/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-91/buggy/testcases b/OCaml/diff-91/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-91/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-91/metadata.json b/OCaml/diff-91/metadata.json new file mode 100644 index 000000000..511db7f6e --- /dev/null +++ b/OCaml/diff-91/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-91", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-92/.dockerignore b/OCaml/diff-92/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-92/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-92/Dockerfile b/OCaml/diff-92/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-92/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-92/buggy/src.ml b/OCaml/diff-92/buggy/src.ml new file mode 100644 index 000000000..6da82ea39 --- /dev/null +++ b/OCaml/diff-92/buggy/src.ml @@ -0,0 +1,13 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (env : string)) : aexp = + match exp with + | Const a -> Const 0 + | Var x -> if x = env then Const 1 else Var x + | Power (s, i) -> + if s = env then Times [ Const i; Power (s, i - 1) ] else Power (s, i) diff --git a/OCaml/diff-92/buggy/test.ml b/OCaml/diff-92/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-92/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-92/buggy/testcases b/OCaml/diff-92/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-92/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-92/metadata.json b/OCaml/diff-92/metadata.json new file mode 100644 index 000000000..2b09e4d01 --- /dev/null +++ b/OCaml/diff-92/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-92", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-93/.dockerignore b/OCaml/diff-93/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-93/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-93/Dockerfile b/OCaml/diff-93/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-93/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-93/buggy/src.ml b/OCaml/diff-93/buggy/src.ml new file mode 100644 index 000000000..befaccb61 --- /dev/null +++ b/OCaml/diff-93/buggy/src.ml @@ -0,0 +1,24 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const n -> Const 0 + | Var v -> if v = var then Const 1 else Var v + | Power (v, n) -> + if v = var then Times [ Const n; Power (v, n - 1) ] else Const 0 + | Times li -> ( + match li with + | [] -> Const 0 + | hd :: tl -> + Sum + [ Times (diff (hd, var) :: tl); Times [ hd; diff (Times tl, var) ] ] + ) + | Sum li -> ( + match li with + | [] -> Const 0 + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) diff --git a/OCaml/diff-93/buggy/test.ml b/OCaml/diff-93/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-93/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-93/buggy/testcases b/OCaml/diff-93/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-93/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-93/metadata.json b/OCaml/diff-93/metadata.json new file mode 100644 index 000000000..2ad9f543e --- /dev/null +++ b/OCaml/diff-93/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-93", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-94/.dockerignore b/OCaml/diff-94/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-94/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-94/Dockerfile b/OCaml/diff-94/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-94/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-94/buggy/src.ml b/OCaml/diff-94/buggy/src.ml new file mode 100644 index 000000000..d9a06c5f1 --- /dev/null +++ b/OCaml/diff-94/buggy/src.ml @@ -0,0 +1,54 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec hasVar ((exp : aexp list), (var : string)) : bool = + match exp with + | hd :: tl -> + ( match hd with + | Const x -> false + | Var x -> if x = var then true else false + | Power (x, y) -> + if x = var then if y != 0 then true else false else false + | Times l -> hasVar (l, var) + | Sum l -> hasVar (l, var) ) + || hasVar (tl, var) + | [] -> false + + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Power (x, y) -> + if x = var then + if y = 0 then Const 0 + else if y = 1 then Const y + else Times [ Const y; Power (x, y - 1) ] + else if y = 0 then Var x + else Power (x, y) + | Const x -> Const 0 + | Var x -> if x = var then Const 1 else Const 0 + | Sum l -> ( + match l with + | [] -> Const 0 + | [ x ] -> diff (x, var) + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] ) + | Times l -> ( + let flag : bool = hasVar (l, var) in + + match l with + | [] -> Const 0 + | [ x ] -> + if flag = true then + if diff (x, var) = Const 0 then x else diff (x, var) + else Const 0 + | hd :: tl -> + Times + [ + ( if flag = true then + if diff (hd, var) = Const 0 then hd else diff (hd, var) + else Const 0 ); + diff (Times tl, var); + ] ) diff --git a/OCaml/diff-94/buggy/test.ml b/OCaml/diff-94/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-94/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-94/buggy/testcases b/OCaml/diff-94/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-94/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-94/metadata.json b/OCaml/diff-94/metadata.json new file mode 100644 index 000000000..95fc1f99b --- /dev/null +++ b/OCaml/diff-94/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-94", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-95/.dockerignore b/OCaml/diff-95/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-95/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-95/Dockerfile b/OCaml/diff-95/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-95/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-95/buggy/src.ml b/OCaml/diff-95/buggy/src.ml new file mode 100644 index 000000000..477e14994 --- /dev/null +++ b/OCaml/diff-95/buggy/src.ml @@ -0,0 +1,21 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const a -> Const a + | Var x -> Var x + | Power (x, n) -> + if x = var then Times [ Const n; Power (x, n - 1) ] else Power (x, n) + | Times l -> ( + match l with + | [] -> raise (Failure "error") + | h :: t -> Sum [ Times (diff (h, var) :: t); diff (h, var) ] ) + | Sum m -> ( + match m with + | [] -> raise (Failure "error") + | h :: t -> Sum [ diff (h, var); diff (h, var) ] ) diff --git a/OCaml/diff-95/buggy/test.ml b/OCaml/diff-95/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-95/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-95/buggy/testcases b/OCaml/diff-95/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-95/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-95/metadata.json b/OCaml/diff-95/metadata.json new file mode 100644 index 000000000..8a83d8c2a --- /dev/null +++ b/OCaml/diff-95/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-95", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-96/.dockerignore b/OCaml/diff-96/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-96/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-96/Dockerfile b/OCaml/diff-96/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-96/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-96/buggy/src.ml b/OCaml/diff-96/buggy/src.ml new file mode 100644 index 000000000..e32d800e7 --- /dev/null +++ b/OCaml/diff-96/buggy/src.ml @@ -0,0 +1,26 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const a -> Const 0 + | Var a -> if var = a then Const 1 else Var a + | Power (a, b) -> + if var = a then Times [ Const b; Power (a, b - 1) ] else Power (a, b) + | Times a -> ( + match a with + | hd :: tl -> + Sum + [ + Times ([ diff (hd, var) ] @ tl); + Times [ hd; diff (Times tl, var) ]; + ] + | [] -> Const 0 ) + | Sum a -> ( + match a with + | hd :: tl -> Sum [ diff (hd, var); diff (Sum tl, var) ] + | [] -> Const 0 ) diff --git a/OCaml/diff-96/buggy/test.ml b/OCaml/diff-96/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-96/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-96/buggy/testcases b/OCaml/diff-96/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-96/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-96/metadata.json b/OCaml/diff-96/metadata.json new file mode 100644 index 000000000..eae769456 --- /dev/null +++ b/OCaml/diff-96/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-96", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-97/.dockerignore b/OCaml/diff-97/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-97/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-97/Dockerfile b/OCaml/diff-97/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-97/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-97/buggy/src.ml b/OCaml/diff-97/buggy/src.ml new file mode 100644 index 000000000..01183e751 --- /dev/null +++ b/OCaml/diff-97/buggy/src.ml @@ -0,0 +1,39 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + let rec t2 (vl : aexp list) (var : string) : aexp list = + match vl with + | [] -> [] + | hd :: tl -> [ Times ([ diff (hd, var) ] @ tl); Times (hd :: t2 tl var) ] + in + + let rec t (el : aexp list) (c : int) (vl : aexp list) (var : string) : aexp = + match el with + | [] -> Times [ Const c; Sum (t2 vl var) ] + | hd :: tl -> ( + match hd with + | Const x -> t tl (c * x) vl var + | a -> t tl c (vl @ [ a ]) var ) + in + + let rec s (el : aexp list) (l : aexp list) (var : string) : aexp = + match el with [] -> Sum l | hd :: tl -> s tl (l @ [ diff (hd, var) ]) var + in + + match exp with + | Const x -> Const 0 + | Var x -> if x = var then Const 1 else Const 0 + | Power (x, y) -> + if x = var then + if y = 0 then Const 0 + else if y = 1 then diff (Var x, var) + else if y = 2 then Times [ Const 2; Var x ] + else Times [ Const y; Power (x, y - 1) ] + else Const 0 + | Times l -> t l 1 [] var + | Sum l -> s l [] var diff --git a/OCaml/diff-97/buggy/test.ml b/OCaml/diff-97/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-97/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-97/buggy/testcases b/OCaml/diff-97/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-97/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-97/metadata.json b/OCaml/diff-97/metadata.json new file mode 100644 index 000000000..cf8a6a564 --- /dev/null +++ b/OCaml/diff-97/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-97", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-98/.dockerignore b/OCaml/diff-98/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-98/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-98/Dockerfile b/OCaml/diff-98/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-98/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-98/buggy/src.ml b/OCaml/diff-98/buggy/src.ml new file mode 100644 index 000000000..ec89fec2c --- /dev/null +++ b/OCaml/diff-98/buggy/src.ml @@ -0,0 +1,23 @@ +exception NotImplemented + +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const n -> Const 0 + | Var k -> if k = var then Const 1 else Const 1 + | Power (k, n) -> + if k = var then Times [ Const n; Power (k, n - 1) ] else Const 0 + | Times (hd :: tl) -> + if tl = [] then diff (hd, var) + else if diff (hd, var) = Const 0 then Times [ hd; diff (Times tl, var) ] + else Times [ diff (hd, var); diff (Times tl, var) ] + | Sum (hd :: tl) -> + if tl = [] then diff (hd, var) + else Sum [ diff (hd, var); diff (Sum tl, var) ] + | _ -> raise NotImplemented diff --git a/OCaml/diff-98/buggy/test.ml b/OCaml/diff-98/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-98/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-98/buggy/testcases b/OCaml/diff-98/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-98/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-98/metadata.json b/OCaml/diff-98/metadata.json new file mode 100644 index 000000000..82de27f05 --- /dev/null +++ b/OCaml/diff-98/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-98", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file diff --git a/OCaml/diff-99/.dockerignore b/OCaml/diff-99/.dockerignore new file mode 100644 index 000000000..9a715f53b --- /dev/null +++ b/OCaml/diff-99/.dockerignore @@ -0,0 +1,2 @@ +.dockerignore +Dockerfile \ No newline at end of file diff --git a/OCaml/diff-99/Dockerfile b/OCaml/diff-99/Dockerfile new file mode 100644 index 000000000..852cfbd77 --- /dev/null +++ b/OCaml/diff-99/Dockerfile @@ -0,0 +1,6 @@ +FROM ghcr.io/sambyeol/ocaml-devcontainer:4.14.1-debian-root + +USER root +RUN mkdir -p /workspace +WORKDIR /workspace +COPY . /workspace \ No newline at end of file diff --git a/OCaml/diff-99/buggy/src.ml b/OCaml/diff-99/buggy/src.ml new file mode 100644 index 000000000..c5150ec37 --- /dev/null +++ b/OCaml/diff-99/buggy/src.ml @@ -0,0 +1,22 @@ +type aexp = + | Const of int + | Var of string + | Power of (string * int) + | Times of aexp list + | Sum of aexp list + +let rec diff ((exp : aexp), (var : string)) : aexp = + match exp with + | Const n -> Const 0 + | Var x -> if x = var then Const 1 else Var x + | Power (x, n) -> + if x = var then Times [ Const n; Power (x, n - 1) ] else Power (x, n) + | Times l -> ( + match l with + | [] -> raise (Failure "Times error") + | h :: t -> + Sum [ Times (diff (h, var) :: t); Times [ h; diff (Times t, var) ] ] ) + | Sum l -> ( + match l with + | [] -> raise (Failure "Sum error") + | h :: t -> Sum [ diff (h, var); diff (Sum t, var) ] ) diff --git a/OCaml/diff-99/buggy/test.ml b/OCaml/diff-99/buggy/test.ml new file mode 100644 index 000000000..f178142f4 --- /dev/null +++ b/OCaml/diff-99/buggy/test.ml @@ -0,0 +1,61 @@ +open Src + +type env = (string * int) list + +(* Input checker *) +let rec gather_vars : aexp -> string list -> string list += fun ae vars -> + match ae with + | Const n -> vars + | Var x | Power (x, _) -> x::vars + | Times l | Sum l -> List.fold_left (fun vars ae -> gather_vars ae vars) vars l + +let rec gather_vars2 : env -> string list -> string list += fun env vars -> + match env with + | [] -> vars + | (x, v)::tl -> gather_vars2 tl (x::vars) + +let rec all_bound : string list -> string list -> bool += fun vars1 vars2 -> + match vars1 with + | [] -> true + | hd::tl -> if (List.mem hd vars2) then all_bound tl vars2 else false + +let input_check : aexp -> env -> bool += fun ae env -> + let (vars1, vars2) = (gather_vars ae [], gather_vars2 env []) in + all_bound vars1 vars2 + +let rec find_env : env -> string -> int += fun env x -> + match env with + | [] -> raise (Failure (x ^ "Not Found")) + | (y, v)::tl -> if (y = x) then v else find_env tl x + +let rec ae_eval : aexp -> (string * int) list -> int += fun e env -> + match e with + | Const n -> n + | Var x -> find_env env x + | Power (x, n) -> + if (n <= 0) then 1 else (find_env env x) * (ae_eval (Power (x, n-1)) env) + | Times l -> + begin + match l with + | [] -> 1 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) * (ae_eval (Times tl) env) + end + | Sum l -> + begin + match l with + | [] -> 0 + | [hd] -> ae_eval hd env + | hd::tl -> (ae_eval hd env) + (ae_eval (Sum tl) env) + end + +let grading : (aexp * string) -> env -> int += fun (ae, str) env -> + let diff_result = diff (ae, str) in + if input_check ae env then ae_eval diff_result env else raise (Failure "Invalid") \ No newline at end of file diff --git a/OCaml/diff-99/buggy/testcases b/OCaml/diff-99/buggy/testcases new file mode 100644 index 000000000..c80993394 --- /dev/null +++ b/OCaml/diff-99/buggy/testcases @@ -0,0 +1,31 @@ +{ + (Const 1,"x") ; [("x",1)] => 0; + (Var "y","x") ; [("y",1)] => 0; + (Power ("x", 1), "y") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 2)] => 1; + (Power ("x", 0), "x") ; [("x", 1)] => 0; + (Power ("x", 1), "x") ; [("x", 1)] => 1; + (Power ("x", 2),"y") ; [("x",5)] => 0; + (Power ("y", 5), "y") ; [("y", 2)] => 80; + (Times [Var "x"], "x") ; [("x", 3)] => 1; + (Times [Var "x"; Var "x"], "x") ; [("x", 0)] => 0; + (Times [Var "x"; Var "x"], "x") ; [("x", 1)] => 2; + (Times [Const 1], "x") ; [("x", 1)] => 0; + (Times ([Const 1; Var "x"]), "x") ; [("x", 1)] => 1; + (Sum [Const 0; Var "x"],"x") ; [("x",10)] => 1; + (Sum [Power ("x", 2); Times [Const 2; Var "x"]; Const 1], "x") ; [("x", 2)] => 6; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "x") ; [("x",3)] => 12; + (Sum [Power ("x", 2); Power ("x", 2); Const 1], "y") ; [("x",1)] => 0; + (Sum [Const 2; Power ("x",2); Power ("x",3)], "x") ; ["x",2] => 16; + (Times ([Const (-1); Const (-1); Var "x"]), "x") ; [("x", 1)] => 1; + (Times [Power ("x", 3); Power ("y", 2)], "x") ; [("x", 10); ("y", 5)] => 7500; + (Sum [Times [Sum [Var "x"; Var "y"]; Times [Var "x"; Var "y"]]; Power ("x", 2)], "x") ; [("x", 3); ("y", 4)] => 46; + (Times [Times [Sum [Var "x"; Var "y"]; Var "x"]; Var "x"], "x") ; [("x", 2); ("y", 5)] => 32; + (Times [Const 2; Sum [Var "x"; Var "y"]; Power ("x", 3)], "x") ; [("x", 2); ("y", 1)] => 88; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "x") ; [("x", 2); ("y", 1); ("z", 1)] => 188; + (Times [Sum [Var "x"; Var "y"; Var "z"]; Power ("x", 2); Sum[Times [Const 3; Var "x"]; Var "z"]], "y") ; [("x", 1); ("y", 1); ("z", 1)] => 4; + (Sum ([Var ("x"); Var ("x")]), "x") ;[("x", 1)] => 2; + (Sum ([Const (1)]), "x") ;[("x", 1)] => 0; + (Times ([Var ("x")]), "x") ;[("x", 1)] => 1; +} + diff --git a/OCaml/diff-99/metadata.json b/OCaml/diff-99/metadata.json new file mode 100644 index 000000000..344b72f02 --- /dev/null +++ b/OCaml/diff-99/metadata.json @@ -0,0 +1,12 @@ +{ + "language": "ocaml", + "id": "diff-99", + + "buggyPath": "buggy", + "referencePath": null, + + "buildCommand": "ocamlc src.ml test.ml", + "testCommand": null, + + "categories": ["functional"] +} \ No newline at end of file