Properly class-cast inside CmpOp

There where some instances where class casting
was throwing exceptions. This should prevent
those issues from happening when a primative
Integer comes down the pipe - now with unit tests!