<commit_before>#!/usr/bin/perl -w

use strict;
use warnings;

use utf8;

use Test::More;
use Test::Number::Delta relative => 1.001;
use Log::Any::Adapter 'TAP';

use ProductOpener::Tags qw/:all/;
use ProductOpener::Food qw/:all/;

# Based on https://de.wikipedia.org/w/index.php?title=Wasserh%C3%A4rte&oldid=160348959#Einheiten_und_Umrechnung
is( mmoll_to_unit(1, 'mol/l'), 0.001 );
is( mmoll_to_unit('1', 'moll/l'), 1 );
is( mmoll_to_unit(1, 'mmol/l'), 1 );
is( mmoll_to_unit(1, 'mval/l'), 2 );
is( mmoll_to_unit(1, 'ppm'), 100 );
is( mmoll_to_unit(1, "\N{U+00B0}rH"), 40.080 );
is( mmoll_to_unit(1, "\N{U+00B0}fH"), 10.00 );
is( mmoll_to_unit(1, "\N{U+00B0}e"), 7.02 );
is( mmoll_to_unit(1, "\N{U+00B0}dH"), 5.6 );
is( mmoll_to_unit(1, 'gpg'), 5.847 );

is( unit_to_mmoll(1, 'mol/l'), 1000 );
is( unit_to_mmoll('1', 'mmol/l'), 1 );
is( unit_to_mmoll(1, 'mmol/l'), 1 );
is( unit_to_mmoll(1, 'mval/l'), 0.5 );
is( unit_to_mmoll(1, 'ppm'), 0.01 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}rH"), 0.025 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}fH"), 0.1 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}e"), 0.142 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}dH"), 0.1783 );
delta_ok( unit_to_mmoll(1, 'gpg'), 0.171 );

is( mmoll_to_unit(unit_to_mmoll(1, 'ppm'), "\N{U+00B0}dH"), 0.056 );

# Chinese Measurements Source: http://www.new-chinese.org/lernwortschatz-chinesisch-masseinheiten.html
# kè - gram
is( normalize_quantity("42\N{U+514B}"), 42 );
is( normalize_serving_size("42\N{U+514B}"), 42 );
is( unit_to_g(42, "\N{U+514B}"), 42 );
is( g_to_unit(42, "\N{U+514B}"), 42 );
# héokè - milligram
is( normalize_quantity("42000\N{U+6BEB}\N{U+514B}"), 42 );
is( normalize_serving_size("42000\N{U+6BEB}\N{U+514B}"), 42 );
is( unit_to_g(42000, "\N{U+6BEB}\N{U+514B}"), 42 );
is( g_to_unit(42, "\N{U+6BEB}\N{U+514B}"), 42000 );
# jīn - pound 500 g
is( normalize_quantity("84\N{U+65A4}"), 42000 );
is( normalize_serving_size("84\N{U+65A4}"), 42000 );
is( unit_to_g(84, "\N{U+65A4}"), 42000 );
is( g_to_unit(42000, "\N{U+65A4}"), 84 );
# gōngjīn - kg
is( normalize_quantity("42\N{U+516C}\N{U+65A4}"), 42000 );
is( normalize_serving_size("42\N{U+516C}\N{U+65A4}"), 42000 );
is( unit_to_g(42, "\N{U+516C}\N{U+65A4}"), 42000 );
is( g_to_unit(42000, "\N{U+516C}\N{U+65A4}"), 42 );
# háoshēng - milliliter
is( normalize_quantity("42\N{U+6BEB}\N{U+5347}"), 42 );
is( normalize_serving_size("42\N{U+6BEB}\N{U+5347}"), 42 );
is( unit_to_g(42, "\N{U+6BEB}\N{U+5347}"), 42 );
is( g_to_unit(42, "\N{U+6BEB}\N{U+5347}"), 42 );
# gōngshēng - liter
is( normalize_quantity("42\N{U+516C}\N{U+5347}"), 42000 );
is( normalize_serving_size("42\N{U+516C}\N{U+5347}"), 42000 );
is( unit_to_g(42, "\N{U+516C}\N{U+5347}"), 42000 );
is( g_to_unit(42000, "\N{U+516C}\N{U+5347}"), 42 );

# Russian units
<commit_msg>Add gōngkè - gram - 公克 (in use at least in Taïwan)<commit_after>#!/usr/bin/perl -w

use strict;
use warnings;

use utf8;

use Test::More;
use Test::Number::Delta relative => 1.001;
use Log::Any::Adapter 'TAP';

use ProductOpener::Tags qw/:all/;
use ProductOpener::Food qw/:all/;

# Based on https://de.wikipedia.org/w/index.php?title=Wasserh%C3%A4rte&oldid=160348959#Einheiten_und_Umrechnung
is( mmoll_to_unit(1, 'mol/l'), 0.001 );
is( mmoll_to_unit('1', 'moll/l'), 1 );
is( mmoll_to_unit(1, 'mmol/l'), 1 );
is( mmoll_to_unit(1, 'mval/l'), 2 );
is( mmoll_to_unit(1, 'ppm'), 100 );
is( mmoll_to_unit(1, "\N{U+00B0}rH"), 40.080 );
is( mmoll_to_unit(1, "\N{U+00B0}fH"), 10.00 );
is( mmoll_to_unit(1, "\N{U+00B0}e"), 7.02 );
is( mmoll_to_unit(1, "\N{U+00B0}dH"), 5.6 );
is( mmoll_to_unit(1, 'gpg'), 5.847 );

is( unit_to_mmoll(1, 'mol/l'), 1000 );
is( unit_to_mmoll('1', 'mmol/l'), 1 );
is( unit_to_mmoll(1, 'mmol/l'), 1 );
is( unit_to_mmoll(1, 'mval/l'), 0.5 );
is( unit_to_mmoll(1, 'ppm'), 0.01 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}rH"), 0.025 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}fH"), 0.1 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}e"), 0.142 );
delta_ok( unit_to_mmoll(1, "\N{U+00B0}dH"), 0.1783 );
delta_ok( unit_to_mmoll(1, 'gpg'), 0.171 );

is( mmoll_to_unit(unit_to_mmoll(1, 'ppm'), "\N{U+00B0}dH"), 0.056 );

# Chinese Measurements Source: http://www.new-chinese.org/lernwortschatz-chinesisch-masseinheiten.html
# kè - gram - 克
is( normalize_quantity("42\N{U+514B}"), 42 );
is( normalize_serving_size("42\N{U+514B}"), 42 );
is( unit_to_g(42, "\N{U+514B}"), 42 );
is( g_to_unit(42, "\N{U+514B}"), 42 );
# gōngkè - gram - 公克 (in use at least in Taïwan)
is( normalize_quantity("42\N{U+516C}\N{U+514B}"), 42 );
is( normalize_serving_size("42\N{U+516C}\N{U+514B}"), 42 );
is( unit_to_g(42, "\N{U+516C}\N{U+514B}"), 42 );
is( g_to_unit(42, "\N{U+516C}\N{U+514B}"), 42 );
# héokè - milligram - 毫克
is( normalize_quantity("42000\N{U+6BEB}\N{U+514B}"), 42 );
is( normalize_serving_size("42000\N{U+6BEB}\N{U+514B}"), 42 );
is( unit_to_g(42000, "\N{U+6BEB}\N{U+514B}"), 42 );
is( g_to_unit(42, "\N{U+6BEB}\N{U+514B}"), 42000 );
# jīn - pound 500 g - 斤
is( normalize_quantity("84\N{U+65A4}"), 42000 );
is( normalize_serving_size("84\N{U+65A4}"), 42000 );
is( unit_to_g(84, "\N{U+65A4}"), 42000 );
is( g_to_unit(42000, "\N{U+65A4}"), 84 );
# gōngjīn - kg - 公斤
is( normalize_quantity("42\N{U+516C}\N{U+65A4}"), 42000 );
is( normalize_serving_size("42\N{U+516C}\N{U+65A4}"), 42000 );
is( unit_to_g(42, "\N{U+516C}\N{U+65A4}"), 42000 );
is( g_to_unit(42000, "\N{U+516C}\N{U+65A4}"), 42 );
# háoshēng - milliliter - 毫升
is( normalize_quantity("42\N{U+6BEB}\N{U+5347}"), 42 );
is( normalize_serving_size("42\N{U+6BEB}\N{U+5347}"), 42 );
is( unit_to_g(42, "\N{U+6BEB}\N{U+5347}"), 42 );
is( g_to_unit(42, "\N{U+6BEB}\N{U+5347}"), 42 );
# gōngshēng - liter - 公升
is( normalize_quantity("42\N{U+516C}\N{U+5347}"), 42000 );
is( normalize_serving_size("42\N{U+516C}\N{U+5347}"), 42000 );
is( unit_to_g(42, "\N{U+516C}\N{U+5347}"), 42000 );
is( g_to_unit(42000, "\N{U+516C}\N{U+5347}"), 42 );

# Russian units

{'fraction_non_alphanumeric': 0.2536676902081201, 'fraction_numerical': 0.13817809621289662, 'mean_word_length': 5.930260047281324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6103602', 'n_tokens_mistral': 3533, 'n_tokens_neox': 2975, 'n_words': 468}