Skip to content

Page 626: Unit test for minmax function fails. #138

@WraithGlade

Description

@WraithGlade

However, after I changed the test to the following code then it passed:

TEST_CASE("max and min")
{
	using namespace std::literals;
	auto length_compare = [](const auto& x1, const auto& x2) 
	{ 
		return x1.length() < x2.length(); 
	};

	REQUIRE(min("undiscriminativeness"s, "vermin"s, length_compare) == "vermin");

	REQUIRE(max("maxim"s, "ultramaximal"s, length_compare) == "ultramaximal");

	const string str1 = "minimaxes"s;
	const string str2 = "maximin"s;
	const auto result = minmax(str1, str2, length_compare);
	REQUIRE(result.first == "maximin");
	REQUIRE(result.second == "minimaxes");
}

Notice the main change:

	const string str1 = "minimaxes"s;
	const string str2 = "maximin"s;
	const auto result = minmax(str1, str2, length_compare);

It seems to not like the literal string values "minimaxes"s and "maximin"s and wants them to be assigned to variables. Hence the above code change.

This seems a bit odd to me (the fact that it won't accept literals etc). I'm not sure why it's designed to behave this way.

(PS: I'm using C++17 in Visual Studio 2019, using Microsoft's compiler, not clang, in case that's relevant.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions