2019-12-16 02:33:26 +00:00
|
|
|
#include <string>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <clocale>
|
2019-12-25 07:00:53 +00:00
|
|
|
#include "internal.h"
|
2019-12-16 02:33:26 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("RGBtoANSIWhite") {
|
2019-12-16 02:33:26 +00:00
|
|
|
unsigned r, g, b;
|
2019-12-16 22:36:00 +00:00
|
|
|
for(r = 250 ; r < 256 ; ++r){
|
|
|
|
g = b = r;
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(15 == rgb_quantize_256(r, g, b));
|
2019-12-16 22:36:00 +00:00
|
|
|
}
|
2019-12-16 02:33:26 +00:00
|
|
|
}
|
2019-12-16 04:13:13 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("RGBtoANSIBlack") {
|
2019-12-16 04:13:13 +00:00
|
|
|
unsigned r, g, b;
|
2019-12-16 22:36:00 +00:00
|
|
|
for(r = 0 ; r < 10 ; ++r){
|
|
|
|
g = b = r;
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == rgb_quantize_256(r, g, b));
|
2019-12-16 22:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("RGBtoANSIGrey") {
|
2019-12-16 22:36:00 +00:00
|
|
|
unsigned r, g, b;
|
|
|
|
for(r = 10 ; r < 244 ; ++r){
|
|
|
|
g = b = r;
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(231 + (r * 5) / 49 == rgb_quantize_256(r, g, b));
|
2019-12-16 22:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pure reds are either 0 (black), or 16 plus 36 * [0..5].
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("RGBtoANSIRed") {
|
2019-12-16 22:36:00 +00:00
|
|
|
unsigned r, g, b;
|
|
|
|
g = b = 0x0;
|
|
|
|
for(r = 0 ; r < 256 ; ++r){
|
2019-12-16 22:43:09 +00:00
|
|
|
int c256 = rgb_quantize_256(r, g, b);
|
2019-12-16 22:36:00 +00:00
|
|
|
if(r < 8){
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == c256);
|
2019-12-16 22:36:00 +00:00
|
|
|
}else{
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(15 < c256);
|
|
|
|
CHECK(16 == c256 % 36);
|
2019-12-16 22:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pure greens are either 0 (black), or 16 plus 6 * [0..5].
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("RGBtoANSIGreen") {
|
2019-12-16 22:36:00 +00:00
|
|
|
unsigned r, g, b;
|
|
|
|
r = b = 0x0;
|
|
|
|
for(g = 0 ; g < 256 ; ++g){
|
2019-12-16 22:43:09 +00:00
|
|
|
int c256 = rgb_quantize_256(r, g, b);
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(48 > c256);
|
2019-12-16 22:36:00 +00:00
|
|
|
if(g < 8){
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == c256);
|
2019-12-16 22:36:00 +00:00
|
|
|
}else{
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(15 < c256);
|
|
|
|
CHECK(4 == c256 % 6);
|
2019-12-16 22:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pure blues are either 0 (black), or one of the first 6 colors [16..22].
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("RGBtoANSIBlue") {
|
2019-12-16 22:36:00 +00:00
|
|
|
unsigned r, g, b;
|
|
|
|
r = g = 0x0;
|
|
|
|
for(b = 0 ; b < 256 ; ++b){
|
2019-12-16 22:43:09 +00:00
|
|
|
int c256 = rgb_quantize_256(r, g, b);
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(22 > c256);
|
2019-12-16 22:36:00 +00:00
|
|
|
if(b < 8){
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == c256);
|
2019-12-16 22:36:00 +00:00
|
|
|
}else{
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(15 < c256);
|
2019-12-16 22:36:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-16 04:13:13 +00:00
|
|
|
}
|