Fixed a Bug in the Ray algorithm.

Added more testcases in the ray.