Sha256: 840066e95f9a591ea7650a1e1bd23f11482b231f9a2d33bef104f8f999875088

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require_relative '../test_helper'

describe Skr::Core::Numbers do

    Num = Skr::Core::Numbers


    def test_percnum
        assert Num::PercNum.new( '5%'  ).is_percentage?, "is a percentage"
        assert Num::PercNum.new( '5% ' ).is_percentage?, "is a percentage"
        assert Num::PercNum.new( '5.3 % ' ).is_percentage?, "is a percentage"
        refute Num::PercNum.new( '$5.3 ' ).is_percentage?, "is not a percentage"
        # this is debatable, but we have to draw the line somewhere
        refute Num::PercNum.new( '%5.3 ' ).is_percentage?, "is a percentage"

        assert_equal '95.0',  Num::PercNum.new( '5'  ).debit_from(100).to_s
        assert_equal '95.0',  Num::PercNum.new( '5%' ).debit_from(100).to_s
        assert_equal '105.0', Num::PercNum.new( '5%' ).credit_to(100).to_s
        assert_equal '95.0',  Num::PercNum.new( '-5%').credit_to(100).to_s

        assert_equal '137.38449', Num::PercNum.new( '33.383%' ).credit_to(103).to_s
        assert_equal '68.61551',  Num::PercNum.new( '33.383%' ).debit_from(103).to_s
    end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stockor-core-0.2 test/core/numbers_test.rb