<commit_before>/**
 * test-key2pho.c
 *
 * Copyright (c) 2005
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

#include <stdio.h>
#include <string.h>

#include "testhelper.h"
#include "global.h"
#include "chewing-utf8-util.h"
#include "key2pho-private.h"

int main ()
{
	char *u8phone;
	char rt[10];
	uint16_t phone;
	uint16_t expect;

	u8phone = "\xE3\x84\x86\xE3\x84\xA3" /* ㄆㄣ */;
	phone = UintFromPhone(u8phone);
	expect = 1104;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\x8A\xE3\x84\xA7\xE3\x84\xA2" /* ㄊㄧㄢ */;
	phone = UintFromPhone(u8phone);
	expect = 3272;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\x92\xE3\x84\xA7\xE3\x84\x9A\xCB\x8B" /* ㄒㄧㄚˋ */;
	phone = UintFromPhone(u8phone);
	expect = 7308;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\x8A\xE3\x84\xA7\xE6\xB8\xAC" /* ㄊㄧ測 */;
	phone = UintFromPhone(u8phone);
	expect = 0;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\x8E\xE3\x84\x8E" /* ㄎㄎ */;
	phone = UintFromPhone(u8phone);
	expect = 0;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\xA8\xE3\x84\x8E" /* ㄨㄎ */;
	phone = UintFromPhone(u8phone);
	expect = 0;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	PhoneFromKey( rt, "dj", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8" /* ㄎㄨ */ ), "dj");

	PhoneFromKey( rt, "dj6", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x8A" /* ㄎㄨˊ */ ), "dj6");

	PhoneFromKey( rt, "dj3", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x87" /* ㄎㄨˇ */ ), "dj3");

	PhoneFromKey( rt, "dj4", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x8B" /* ㄎㄨˋ */ ), "dj4");

	PhoneFromKey( rt, "dj7", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x99" /* ㄎㄨ˙ */ ), "dj7");

	return exit_status();
}<commit_msg>Add test cases for PhoneFromUint<commit_after>/**
 * test-key2pho.c
 *
 * Copyright (c) 2005
 *	libchewing Core Team. See ChangeLog for details.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file.
 */

#include <stdio.h>
#include <string.h>

#include "testhelper.h"
#include "global.h"
#include "chewing-utf8-util.h"
#include "key2pho-private.h"
#include "chewing-private.h"

void test_uint_and_phone()
{
	char *u8phone;
	char rt[ MAX_UTF8_SIZE * ZUIN_SIZE + 1 ];
	uint16_t phone;
	uint16_t expect;


	u8phone = "\xE3\x84\x86\xE3\x84\xA3" /* ㄆㄣ */;
	phone = UintFromPhone(u8phone);
	expect = 1104;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	PhoneFromUint( rt, sizeof( rt ), expect );
	ok (strcmp( rt, u8phone ) == 0, "PhoneFromUint d%d' shall be `%s', got `%s'",
		expect, u8phone, rt);


	u8phone = "\xE3\x84\x8A\xE3\x84\xA7\xE3\x84\xA2" /* ㄊㄧㄢ */;
	phone = UintFromPhone(u8phone);
	expect = 3272;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	PhoneFromUint( rt, sizeof( rt ), expect );
	ok (strcmp( rt, u8phone ) == 0, "PhoneFromUint d%d' shall be `%s', got `%s'",
		expect, u8phone, rt);


	u8phone = "\xE3\x84\x92\xE3\x84\xA7\xE3\x84\x9A\xCB\x8B" /* ㄒㄧㄚˋ */;
	phone = UintFromPhone(u8phone);
	expect = 7308;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	PhoneFromUint( rt, sizeof( rt ), expect );
	ok (strcmp( rt, u8phone ) == 0, "PhoneFromUint `%d' shall be `%s', got `%s'",
		expect, u8phone, rt);
}

void test_uint_and_phone_error()
{
	char *u8phone;
	char rt[ MAX_UTF8_SIZE * ZUIN_SIZE + 1 ];
	uint16_t phone;
	uint16_t expect;

	u8phone = "\xE3\x84\x8A\xE3\x84\xA7\xE6\xB8\xAC" /* ㄊㄧ測 */;
	phone = UintFromPhone(u8phone);
	expect = 0;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\x8E\xE3\x84\x8E" /* ㄎㄎ */;
	phone = UintFromPhone(u8phone);
	expect = 0;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	u8phone = "\xE3\x84\xA8\xE3\x84\x8E" /* ㄨㄎ */;
	phone = UintFromPhone(u8phone);
	expect = 0;
	ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'",
		u8phone, expect, phone);

	PhoneFromUint( rt, sizeof( rt ), 0 );
	ok (strcmp( rt, "" ) == 0, "PhoneFromUint `%d' shall be `%s', got `%s'",
		0, "", rt);

}

void test_key_and_phone()
{
	char rt[ MAX_UTF8_SIZE * ZUIN_SIZE + 1 ];

	PhoneFromKey( rt, "dj", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8" /* ㄎㄨ */ ), "dj");

	PhoneFromKey( rt, "dj6", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x8A" /* ㄎㄨˊ */ ), "dj6");

	PhoneFromKey( rt, "dj3", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x87" /* ㄎㄨˇ */ ), "dj3");

	PhoneFromKey( rt, "dj4", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x8B" /* ㄎㄨˋ */ ), "dj4");

	PhoneFromKey( rt, "dj7", 0, 1 );
	ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x99" /* ㄎㄨ˙ */ ), "dj7");
}

int main ()
{
	test_uint_and_phone();
	test_uint_and_phone_error();
	test_key_and_phone();

	return exit_status();
}
{'fraction_non_alphanumeric': 0.21082089552238806, 'fraction_numerical': 0.06809701492537314, 'mean_word_length': 3.673931996512642, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6112373', 'n_tokens_mistral': 2788, 'n_tokens_neox': 2626, 'n_words': 550}