add value_min/value_max

This commit is contained in:
lixianjing 2022-11-07 17:31:41 +08:00
parent 074104c7c3
commit 2e9611ed52
6 changed files with 393 additions and 50 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
2022/11/07
* 增加函数value\_min/value\_max。
2022/11/03
* 导出conf\_node\_count\_children函数(感谢智明提供补丁)
* 修复纯黑做半透明的融合时候颜色不对的问题(感谢智明提供补丁)

View File

@ -732,7 +732,7 @@ ret_t tk_str_append(char* str, uint32_t max_len, const char* s) {
return RET_OK;
}
int32_t tk_str_cmp(const char* a, const char* b) {
int32_t tk_strcmp(const char* a, const char* b) {
if (a == b) {
return 0;
}
@ -748,7 +748,7 @@ int32_t tk_str_cmp(const char* a, const char* b) {
return strcmp(a, b);
}
int32_t tk_str_icmp(const char* a, const char* b) {
int32_t tk_stricmp(const char* a, const char* b) {
if (a == b) {
return 0;
}
@ -764,6 +764,38 @@ int32_t tk_str_icmp(const char* a, const char* b) {
return strcasecmp(a, b);
}
int32_t tk_wstrcmp(const wchar_t* a, const wchar_t* b) {
if (a == b) {
return 0;
}
if (a == NULL) {
return -1;
}
if (b == NULL) {
return 1;
}
return wcscmp(a, b);
}
int32_t tk_wstricmp(const wchar_t* a, const wchar_t* b) {
if (a == b) {
return 0;
}
if (a == NULL) {
return -1;
}
if (b == NULL) {
return 1;
}
return wcscasecmp(a, b);
}
char* tk_str_copy(char* dst, const char* src) {
if (src != NULL) {
uint32_t size = strlen(src) + 1;
@ -1527,10 +1559,11 @@ bool_t tk_is_ui_thread(void) {
return s_ui_thread_id == tk_thread_self();
}
uint32_t tk_strnlen(const char *str, uint32_t maxlen) {
uint32_t tk_strnlen(const char* str, uint32_t maxlen) {
const char* s;
return_value_if_fail(str != NULL, 0);
for (s = str; maxlen-- && *s != '\0'; ++s);
for (s = str; maxlen-- && *s != '\0'; ++s)
;
return s - str;
}

View File

@ -91,7 +91,7 @@ bool_t tk_atob(const char* str);
double tk_atof(const char* str);
/**
* @method tk_str_cmp
* @method tk_strcmp
*
*
*
@ -100,10 +100,10 @@ double tk_atof(const char* str);
*
* @return {int32_t} =-1a为NULL=1b为NULL<0a小于b>0a大于b=0a等于b
*/
int32_t tk_str_cmp(const char* a, const char* b);
int32_t tk_strcmp(const char* a, const char* b);
/**
* @method tk_str_icmp
* @method tk_stricmp
*
*
*
@ -112,7 +112,31 @@ int32_t tk_str_cmp(const char* a, const char* b);
*
* @return {int32_t} =-1a为NULL=1b为NULL<0a小于b>0a大于b=0a等于b
*/
int32_t tk_str_icmp(const char* a, const char* b);
int32_t tk_stricmp(const char* a, const char* b);
/**
* @method tk_wstrcmp
*
*
*
* @param {const wchar_t*} a
* @param {const wchar_t*} b
*
* @return {int32_t} =-1a为NULL=1b为NULL<0a小于b>0a大于b=0a等于b
*/
int32_t tk_wstrcmp(const wchar_t* a, const wchar_t* b);
/**
* @method tk_wstricmp
*
*
*
* @param {const wchar_t*} a
* @param {const wchar_t*} b
*
* @return {int32_t} =-1a为NULL=1b为NULL<0a小于b>0a大于b=0a等于b
*/
int32_t tk_wstricmp(const wchar_t* a, const wchar_t* b);
/**
* @method tk_watoi
@ -343,8 +367,8 @@ uint32_t tk_strlen(const char* str);
* @param {uint32_t}
*
* @return {uint32_t}
*/
uint32_t tk_strnlen(const char *str, uint32_t maxlen);
*/
uint32_t tk_strnlen(const char* str, uint32_t maxlen);
/**
* @method tk_strrstr
@ -906,6 +930,9 @@ ret_t xml_file_expand(const char* filename, str_t* s, const char* data);
#define TK_STRDUP(str) ((str) != NULL) ? strdup(str) : NULL
#define TK_STRNDUP(str) ((str) != NULL) ? strndup(str) : NULL
#define tk_str_cmp tk_strcmp
#define tk_str_icmp tk_stricmp
END_C_DECLS
#endif /*TK_UTILS_H*/

View File

@ -2186,3 +2186,107 @@ ret_t value_expt(value_t* v, value_t* other, value_t* result) {
return RET_OK;
}
ret_t value_min(value_t* arr, uint32_t size, value_t* result) {
uint32_t i = 0;
uint32_t r = 0;
uint32_t type = 0;
return_value_if_fail(arr != NULL && size > 0 && result != NULL, RET_BAD_PARAMS);
type = arr[0].type;
if (type >= VALUE_TYPE_INT8 && type < VALUE_TYPE_UINT64) {
for (i = 0; i < size; i++) {
if (value_int64(arr + i) < value_int64(arr + r)) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type == VALUE_TYPE_UINT64) {
for (i = 0; i < size; i++) {
if (value_uint64(arr + i) < value_uint64(arr + r)) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type == VALUE_TYPE_STRING) {
for (i = 0; i < size; i++) {
if (tk_strcmp(value_str(arr + i), value_str(arr + r)) < 0) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type == VALUE_TYPE_WSTRING) {
for (i = 0; i < size; i++) {
if (tk_wstrcmp(value_wstr(arr + i), value_wstr(arr + r)) < 0) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type >= VALUE_TYPE_FLOAT && type <= VALUE_TYPE_DOUBLE) {
for (i = 0; i < size; i++) {
if (value_double(arr + i) < value_double(arr + r)) {
r = i;
}
}
return value_copy(result, arr + r);
} else {
log_warn("not impl for this type");
return RET_NOT_IMPL;
}
return RET_OK;
}
ret_t value_max(value_t* arr, uint32_t size, value_t* result) {
uint32_t i = 0;
uint32_t r = 0;
uint32_t type = 0;
return_value_if_fail(arr != NULL && size > 0 && result != NULL, RET_BAD_PARAMS);
type = arr[0].type;
if (type >= VALUE_TYPE_INT8 && type < VALUE_TYPE_UINT64) {
for (i = 0; i < size; i++) {
if (value_int64(arr + i) > value_int64(arr + r)) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type == VALUE_TYPE_UINT64) {
for (i = 0; i < size; i++) {
if (value_uint64(arr + i) > value_uint64(arr + r)) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type == VALUE_TYPE_STRING) {
for (i = 0; i < size; i++) {
if (tk_strcmp(value_str(arr + i), value_str(arr + r)) > 0) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type == VALUE_TYPE_WSTRING) {
for (i = 0; i < size; i++) {
if (tk_wstrcmp(value_wstr(arr + i), value_wstr(arr + r)) > 0) {
r = i;
}
}
return value_copy(result, arr + r);
} else if (type >= VALUE_TYPE_FLOAT && type <= VALUE_TYPE_DOUBLE) {
for (i = 0; i < size; i++) {
if (value_double(arr + i) > value_double(arr + r)) {
r = i;
}
}
return value_copy(result, arr + r);
} else {
log_warn("not impl for this type");
return RET_NOT_IMPL;
}
return RET_OK;
}

View File

@ -1123,6 +1123,28 @@ ret_t value_expt(value_t* v, value_t* other, value_t* result);
*/
ret_t value_mod(value_t* v, value_t* other, value_t* result);
/**
* @method value_min
* result对象
* @param {value_t*} arr
* @param {uint32_t} size
* @param {value_t*} result value对象
*
* @return {ret_t} RET_OK表示成功
*/
ret_t value_min(value_t* arr, uint32_t size, value_t* result);
/**
* @method value_max
* result对象
* @param {value_t*} arr
* @param {uint32_t} size
* @param {value_t*} result value对象
*
* @return {ret_t} RET_OK表示成功
*/
ret_t value_max(value_t* arr, uint32_t size, value_t* result);
END_C_DECLS
#endif /*TK_VALUE_H*/

View File

@ -901,7 +901,7 @@ TEST(value, bits) {
value_set_bool(&v, TRUE);
ASSERT_EQ(value_bit_not(&v, &r), RET_OK);
ASSERT_EQ(value_bool(&r), FALSE);
value_set_bool(&v, FALSE);
ASSERT_EQ(value_bit_not(&v, &r), RET_OK);
ASSERT_EQ(value_bool(&r), TRUE);
@ -925,7 +925,7 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_INT8);
ASSERT_EQ(value_int8(&r), (int8_t)0xff);
value_set_uint8(&v1, 0xf0);
value_set_uint8(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
@ -940,7 +940,6 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(r.type, VALUE_TYPE_UINT8);
ASSERT_EQ(value_uint8(&r), (uint8_t)0xff);
value_set_int16(&v1, 0xf0);
value_set_int16(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
@ -954,7 +953,7 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_INT16);
ASSERT_EQ(value_int16(&r), (int16_t)0xff);
value_set_uint16(&v1, 0xf0);
value_set_uint16(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
@ -982,7 +981,7 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_INT32);
ASSERT_EQ(value_int32(&r), (int32_t)0xff);
value_set_uint32(&v1, 0xf0);
value_set_uint32(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
@ -1010,7 +1009,7 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
ASSERT_EQ(value_int64(&r), (int64_t)0xff);
value_set_uint64(&v1, 0xf0);
value_set_uint64(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
@ -1024,19 +1023,19 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_UINT64);
ASSERT_EQ(value_uint64(&r), (uint64_t)0xff);
value_set_int32(&v1, 0xf0);
value_set_int64(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_INT64);
ASSERT_EQ(value_int64(&r), 0);
value_set_uint8(&v1, 0xf0);
value_set_uint32(&v2, 0x0f);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_UINT32);
ASSERT_EQ(value_uint64(&r), 0);
value_set_bool(&v1, TRUE);
value_set_bool(&v2, TRUE);
ASSERT_EQ(value_bit_and(&v1, &v2, &r), RET_OK);
@ -1048,7 +1047,7 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
ASSERT_EQ(value_bool(&r), TRUE);
value_set_bool(&v1, TRUE);
value_set_bool(&v2, TRUE);
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
@ -1066,19 +1065,19 @@ TEST(value, bit_and_or_xor) {
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
ASSERT_EQ(value_bool(&r), TRUE);
value_set_bool(&v1, TRUE);
value_set_bool(&v2, FALSE);
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
ASSERT_EQ(value_bool(&r), TRUE);
value_set_bool(&v1, FALSE);
value_set_bool(&v2, FALSE);
ASSERT_EQ(value_bit_or(&v1, &v2, &r), RET_OK);
ASSERT_EQ(r.type, VALUE_TYPE_BOOL);
ASSERT_EQ(value_bool(&r), FALSE);
value_set_bool(&v1, FALSE);
value_set_bool(&v2, FALSE);
ASSERT_EQ(value_bit_xor(&v1, &v2, &r), RET_OK);
@ -1098,47 +1097,47 @@ TEST(value, abs) {
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_int8(&o), 10);
value_set_int16(&v, -10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_int16(&o), 10);
value_set_int32(&v, -10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_int32(&o), 10);
value_set_uint32(&v, 10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_uint32(&o), 10);
value_set_int64(&v, -10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_int64(&o), 10);
value_set_int64(&v, 10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_int64(&o), 10);
value_set_double(&v, 10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_double(&o), 10);
value_set_double(&v, -10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_double(&o), 10);
value_set_float(&v, 10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
ASSERT_EQ(value_float(&o), 10);
value_set_float(&v, -10);
ASSERT_EQ(value_abs(&v, &o), RET_OK);
ASSERT_EQ(o.type == v.type, TRUE);
@ -1159,15 +1158,15 @@ TEST(value, add_int8) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int8(&o), -2);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int8(&o), 80);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int8(&o), 1);
value_set_int8(&v1, -120);
value_set_int8(&v2, -100);
@ -1178,11 +1177,11 @@ TEST(value, add_int8) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int8(&o), -20);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == VALUE_TYPE_INT16, TRUE);
ASSERT_EQ(value_int16(&o), 120 * 100);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int8(&o), 1);
@ -1202,15 +1201,15 @@ TEST(value, add_int16) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int16(&o), -6);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int16(&o), 160);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int16(&o), 1);
value_set_int16(&v1, -30000);
value_set_int16(&v2, -20000);
@ -1221,11 +1220,11 @@ TEST(value, add_int16) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int16(&o), -10000);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == VALUE_TYPE_INT32, TRUE);
ASSERT_EQ(value_int32(&o), 30000 * 20000);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int16(&o), 1);
@ -1245,11 +1244,11 @@ TEST(value, add_int32) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int32(&o), -32);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int32(&o), 420);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int32(&o), 4);
@ -1269,11 +1268,11 @@ TEST(value, add_int64) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int64(&o), -32);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int64(&o), 420);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_int64(&o), 4);
@ -1293,14 +1292,15 @@ TEST(value, add_double) {
ASSERT_EQ(value_sub(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_double(&o), -32);
ASSERT_EQ(value_mul(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_double(&o), 420);
ASSERT_EQ(value_div(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(tk_fequal(value_double(&o), 4.2), TRUE);;
ASSERT_EQ(tk_fequal(value_double(&o), 4.2), TRUE);
;
}
TEST(value, mod) {
@ -1330,7 +1330,7 @@ TEST(value, mod) {
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
ASSERT_EQ(o.type == v1.type, TRUE);
ASSERT_EQ(value_uint16(&o), 4);
value_set_int32(&v1, 10);
value_set_int32(&v2, 6);
ASSERT_EQ(value_mod(&v1, &v2, &o), RET_OK);
@ -1372,3 +1372,157 @@ TEST(value, expt) {
ASSERT_EQ(tk_fequal(value_double(&o), 0.001), TRUE);
ASSERT_EQ(o.type == VALUE_TYPE_DOUBLE, TRUE);
}
TEST(value, min) {
int32_t i = 0;
value_t v[10];
value_t o;
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int8(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT8);
ASSERT_EQ(value_int8(&o), -8);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint8(v + i, i + 1);
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT8);
ASSERT_EQ(value_uint8(&o), 1);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int16(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT16);
ASSERT_EQ(value_int16(&o), -8);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint16(v + i, i + 1);
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT16);
ASSERT_EQ(value_uint16(&o), 1);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int32(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT32);
ASSERT_EQ(value_int32(&o), -8);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint32(v + i, i + 1);
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT32);
ASSERT_EQ(value_uint32(&o), 1);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int64(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT64);
ASSERT_EQ(value_int64(&o), -8);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint64(v + i, i + 1);
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT64);
ASSERT_EQ(value_uint64(&o), 1);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_double(v + i, i + 1);
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_DOUBLE);
ASSERT_EQ(value_double(&o), 1);
const char* str[] = {"a", "b", "c", "0", "A", "B", "C", "1", "2", "3"};
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_str(v + i, str[i]);
}
ASSERT_EQ(value_min(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_STRING);
ASSERT_STREQ(value_str(&o), "0");
}
TEST(value, max) {
int32_t i = 0;
value_t v[10];
value_t o;
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int8(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT8);
ASSERT_EQ(value_int8(&o), 9);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint8(v + i, i + 1);
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT8);
ASSERT_EQ(value_uint8(&o), 10);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int16(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT16);
ASSERT_EQ(value_int16(&o), 9);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint16(v + i, i + 1);
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT16);
ASSERT_EQ(value_uint16(&o), 10);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int32(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT32);
ASSERT_EQ(value_int32(&o), 9);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint32(v + i, i + 1);
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT32);
ASSERT_EQ(value_uint32(&o), 10);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_int64(v + i, i * ((i % 2 == 0) ? -1 : 1));
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_INT64);
ASSERT_EQ(value_int64(&o), 9);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_uint64(v + i, i + 1);
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_UINT64);
ASSERT_EQ(value_uint64(&o), 10);
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_double(v + i, i + 1);
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_DOUBLE);
ASSERT_EQ(value_double(&o), 10);
const char* str[] = {"a", "b", "c", "0", "A", "B", "C", "1", "2", "3"};
for (i = 0; i < ARRAY_SIZE(v); i++) {
value_set_str(v + i, str[i]);
}
ASSERT_EQ(value_max(v, ARRAY_SIZE(v), &o), RET_OK);
ASSERT_EQ(o.type, VALUE_TYPE_STRING);
ASSERT_STREQ(value_str(&o), "c");
}