60 lines
1.0 KiB
C++
60 lines
1.0 KiB
C++
|
|
#include "solution.cpp"
|
||
|
|
|
||
|
|
#include <cassert>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
int main(int argc, char *argv[]) {
|
||
|
|
(void)argc;
|
||
|
|
(void)argv;
|
||
|
|
|
||
|
|
Solution s;
|
||
|
|
|
||
|
|
// Example 1
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("abba", 2);
|
||
|
|
assert(result == "baab");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Example 2
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("aa", 2);
|
||
|
|
assert(result == "");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Example 3
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("bacab", 1);
|
||
|
|
assert(result == "abcba");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Additional tests
|
||
|
|
|
||
|
|
// Single palindrome
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("aaa", 1);
|
||
|
|
assert(result == "aaa");
|
||
|
|
}
|
||
|
|
|
||
|
|
// k exceeds number of permutations
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("aabb", 3);
|
||
|
|
assert(result == "");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Two different characters
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("aabbcc", 1);
|
||
|
|
assert(result == "abccba");
|
||
|
|
}
|
||
|
|
|
||
|
|
// Already sorted palindrome
|
||
|
|
{
|
||
|
|
std::string result = s.smallestPalindrome("abcba", 2);
|
||
|
|
assert(result == "bacab");
|
||
|
|
}
|
||
|
|
|
||
|
|
std::cout << "All tests passed!\n";
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|