I have a project that is intended to check the correctness of the student program. I currently use an approach like this:
I specify a goal that the student program must achieve.
I change the student program into a sequence of facts and actions (in Prolog), and check if these facts and actions can satisfy the goal.
For an example, if I ask student to write a program to find the total of a + b, and store the result in c, then I will specify the goal to be like this (in Prolog style):
goal:- hasVarName(VarA, a), hasVarValue(VarA, ValA),
hasVarName(VarA, b), hasVarValue(VarB, ValB),
hasVarName(VarC, c), hasVarValue(VarC, ValC),
Total = ValA + ValB,
isEqual(Total, ValC).
This approach works well to check student's sequential program. Then when I try to check student's program that contains conditionals, I just realize that may be I cannot use this approach anymore.
For example, if I ask student to write program to find the discount (in dollar) from total purchasing using this formula:
. (Total purchasing < 50) -> customer gets 5% discount
. (50 <= Total purchasing < 100) -> customer gets 10% discount
. (Total purchasing >= 100) -> customer gets 20% discount
then I cannot just write in my goal, that the value of Discount (in dollar) is just the Total Purchasing * percentage discount.
Some problem that I face:
The value of the percentage discount can vary depending of the value of the Total purchasing (so I cannot have one predicate that can be used to represent the value of the percentage discount)
The value of the Total purchasing is a variable value (input from user) - So I never know the value of this variable. Therefore I cannot determine the value of percentage discount at a certain time as well.
The user can write the IF statement in many variations, as well as the conditional statement inside the IF.
I have been suggested to use the concept of Conditional Planning to solve this kind of problem. But as I read some information about conditional planning, the initial state, the plans, and the goal are specified by us as a programmer. In my case, it looks like that I am the one that must specify the goal, but the initial state and the plans are provided by students by parsing their code.
So I guess, it's a bit different. But, please advise me if my thought is incorrect, and please give me a correction about it.
Or if it is not conditional planning, what kind of approach that I can use to solve this kind of problem (checking correctness of student code) ? Any information whether it is in theoretical point of view or in practical implementation is really appreciated.
I have a thought that probably I should do something like comparing plans, between the student's plan (by parsing his code) and my intended plan. So if the student's plan is the same or superset of my intended plan, then I can say that the student plan/code is correct. But I guess I should do the comparing in a better way than doing pattern matching (cause I guess, It just won't work). But how? Please advice me, if this is the correct approach that I have to do.
Many thanks.
Note: I previously have a related but specific question in this link: How to write kind of Conditional Planning in Prolog?. However, I just realized that those specific question may not be able to help me to solve this general problem.