tuura / scenco-core

Collection of encoding algorithms for conditional graphs
Other
0 stars 1 forks source link

Checking correctness of opcodes generated #10

Closed allegroCoder closed 8 years ago

allegroCoder commented 8 years ago

A function for checking the feasibility / correctness of the opcodes generated by c++ framework is needed. The function should be checking the following aspects:

This function might be a good test for verifying the good implementation of the c++ encoding framework.

snowleopard commented 8 years ago

feasibility

Feasibility is a different property, which is probably more difficult to check than correctness. I suggest to open a separate issue for it. Given an encoding problem (codes with unknowns) the feasibility checking function should return True if and only if it is possible to find a suitable assignment.

correctness of the opcodes generated by c++ framework is needed

This is not only for C++ framework. Checking correctness is useful in general for whatever implementation we will come up with.

snowleopard commented 8 years ago

I will try to implement this function myself.

allegroCoder commented 8 years ago

I agree, correctness checking can be useful also in other cases, not only for c++ opcode generation.

However, I already implemented the feasibility checking in c++. Therefore I can export the function for this purpose.

snowleopard commented 8 years ago

@allegroCoder I see! OK, please export it so we have a basis for comparison. In the meanwhile I will try to implement an equivalent one in Haskell.

allegroCoder commented 8 years ago

I used the checking, as you described, to check if at least one encoding can be generated from the custom assignment (with unknown, known and dont_used bits). Ok I will, would be useful having a basis for comparison, once that you come up with the Haskell function! :-)

snowleopard commented 8 years ago

I've added the following function for code validation to Code.hs:

data CodeValidation = Valid
                    | LengthMismatch
                    | UnusedBitRemoved
                    | UnusedBitAdded
                    | KnownBitChanged

validate :: CodeWithUnknowns -> CodeWithoutUnknowns -> CodeValidation
validate []     []     = Valid
validate []     _      = LengthMismatch
validate _      []     = LengthMismatch
validate (a:as) (b:bs)
    | a == unused      = (b /= unused    ) `thenError` UnusedBitRemoved
    | a == unknown     = (b == unused    ) `thenError` UnusedBitAdded
    | a == known True  = (b /= used True ) `thenError` KnownBitChanged
    | a == known False = (b /= used False) `thenError` KnownBitChanged
  where
    condition `thenError` result = if condition then result else validate as bs

I think we should use this in tests. And we shouldn't forget to test this function too! :)

@allegroCoder Please cross check this function with your C++ implementation and reopen the issue if you spot any errors. If the function is correct then I don't think we need to import C++ implementation.