Also add test cases to check consistency of the results. original commit: 71b500b49f2948b7c6902afe2a03938e55eb9423