File: src/Tests/Unit/BaseConverterTest.php

Recommend this page to a friend!
  Classes of FN  >  PHP Base Converter  >  src/Tests/Unit/BaseConverterTest.php  >  Download  
File: src/Tests/Unit/BaseConverterTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: PHP Base Converter
Convert number representations between two bases
Author: By
Last change:
Date: 1 year ago
Size: 2,676 bytes
 

Contents

Class file image Download
<?php
/**
 * BaseConverter.
 *
 * @author Frank Nägler <mail@naegler.net>
 *
 * @link https://github.com/NeoBlack/BaseConverter
 */

namespace NeoBlack\BaseConverter\Tests\Unit;

use
NeoBlack\BaseConverter\BaseConverter;

/**
 * Class BaseConverterTest.
 */
class BaseConverterTest extends BaseTestCase
{
   
/**
     * @return array
     */
   
public function baseTestDataProvider()
    {
        return [
           
'1 16base' => [1, '1', BaseConverter::BASE16],
           
'1 32base' => [1, '1', BaseConverter::BASE32],
           
'1 62base' => [1, '1', BaseConverter::BASE62],
           
'1 64base' => [1, '1', BaseConverter::BASE64],
           
'100 16base' => [100, '64', BaseConverter::BASE16],
           
'100 32base' => [100, '34', BaseConverter::BASE32],
           
'100 62base' => [100, '1C', BaseConverter::BASE62],
           
'100 64base' => [100, '1A', BaseConverter::BASE64],
           
'1000 16base' => [1000, '3E8', BaseConverter::BASE16],
           
'1000 32base' => [1000, 'V8', BaseConverter::BASE32],
           
'1000 62base' => [1000, 'g8', BaseConverter::BASE62],
           
'1000 64base' => [1000, 'fE', BaseConverter::BASE64],
        ];
    }

    public function
basesDataProvider()
    {
        return [
           
'16base' => [BaseConverter::BASE16],
           
'32base' => [BaseConverter::BASE32],
           
'62base' => [BaseConverter::BASE62],
           
'64base' => [BaseConverter::BASE64],
        ];
    }

   
/**
     * @param int $tenBaseValue
     * @param string $xBaseValue
     * @param string $base
     * @test
     * @dataProvider baseTestDataProvider
     */
   
public function to10BaseReturnCorrectValue($tenBaseValue, $xBaseValue, $base)
    {
        static::
assertEquals($tenBaseValue, BaseConverter::to10Base($xBaseValue, $base));
    }

   
/**
     * @param int $tenBaseValue
     * @param string $xBaseValue
     * @param string $base
     * @test
     * @dataProvider baseTestDataProvider
     */
   
public function toBaseReturnCorrectValue($tenBaseValue, $xBaseValue, $base)
    {
        static::
assertEquals($xBaseValue, BaseConverter::toBase($tenBaseValue, $base));
    }

   
/**
     * @param string $base
     * @test
     * @dataProvider basesDataProvider
     */
   
public function ensureConversionInBothDirectionsWorksForDifferentBases($base)
    {
       
$input = range(0, 10000);
       
$expected = [];
        foreach (
$input as $number) {
           
$expected[$number] = BaseConverter::toBase($number, $base);
        }
        foreach (
$expected as $tenBase => $baseValue) {
            static::
assertEquals($tenBase, BaseConverter::to10Base($baseValue, $base));
        }
    }
}


For more information send a message to info at phpclasses dot org.