Pawn::Color Pawn::GetColor() const
{
return m_color;
}
Pawn& Pawn::operator=(const Pawn& other)
{
m_color = other.m_color;
return *this;
}
std::ostream& operator<<(std::ostream& os, const Pawn& pawn)
{
return os << pawn.m_color;
}
我想对运算符<<
进行单元测试,以测试输出后的颜色是否保持不变。
我尝试过类似的操作,但失败了:
TEST_METHOD(outputOperator)
{
Pawn pawn(Pawn::Color::Blue);
std::stringstream out;
out << pawn.GetColor();
//Assert::IsTrue(out.str() == pawn.GetColor());
/*if (out.str() != "Blue") {
Assert::Fail();
}*/
}