/** * @param bool $realNumber * @param string $input * @param string $output * @dataProvider numberProvider */ public function testCorrect(bool $realNumber, string $input, string $output) { $validator = new NumberValidator($realNumber); $validator->setLogger($this); $this->assertSame($output, $validator->correct($input)); $this->assertSame($input === $output ? [] : [\Psr\Log\LogLevel::ERROR], $this->logLevels); }
/** * 一つのお題を表す配列を、CSVのレコードに変換します。 * @param (string|string[]|float)[][] $word * @param string[] $fieldNames * @param (string|string[])[] $metadata * @return string[] */ protected function convertWordToRecord(array $word, array $fieldNames, array $metadata) : array { $numberValidator = new NumberValidator(); $output = []; foreach ($fieldNames as $fieldName) { $field = isset($word[$fieldName][0]) ? array_shift($word[$fieldName]) : (isset($metadata[$fieldName]) ? $metadata[$fieldName] : ''); if (is_array($field)) { $field = $field['lml']; } elseif (is_float($field)) { $field = $numberValidator->serializeFloat($field); } $output[] = $field; } return $output; }
/** * Validate an Integer Field * * Integers must be numerical and within the specific range. Any decimal component * is rounded off (does not generate any error as long as it is within range). * * @param string $data Field data * @return string This function may alter data before validating it, if so this is the result * @throws FieldException, FieldSizeException */ public function validate($data) { return intval(parent::validate($data)); }
/** * @param $fromPaper * @return \KataBank\Number */ public function read($fromPaper) { $number = $this->builder->build($fromPaper); $this->validator->validate($number); return $number; }
public function tidy($value) { return floor(parent::tidy($value)); }
public function tidy($value) { return round(parent::tidy($value), $this->_decimalPlaces); }