2  * Copyright 2010-2013 Ben Birch
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this software except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *   http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  16 describe("app.ut.byteSize_template", function() {
 
  18         describe("byteSize_template()", function() {
 
  19                 var byteSize_template = window.app.ut.byteSize_template;
 
  21                 it("should postfix with a B and have not decimal for number less than 1000", function() {
 
  22                         expect( byteSize_template( 0 ) ).toBe( "0B" );
 
  23                         expect( byteSize_template( 1 ) ).toBe( "1B" );
 
  24                         expect( byteSize_template( 10 ) ).toBe( "10B" );
 
  25                         expect( byteSize_template( 100 ) ).toBe( "100B" );
 
  26                         expect( byteSize_template( 999 ) ).toBe( "999B" );
 
  29                 it("should have 0.xxX for values between 1000 and 1023", function() {
 
  30                         expect( byteSize_template( 1000  ) ).toBe( "0.98ki" );
 
  31                         expect( byteSize_template( 1024 * 1000 ) ).toBe( "0.98Mi" );
 
  34                 it("should always have three significant digits", function() {
 
  35                         expect( byteSize_template( 1023  ) ).toBe( "1.00ki" );
 
  36                         expect( byteSize_template( 1024  ) ).toBe( "1.00ki" );
 
  37                         expect( byteSize_template( 1025  ) ).toBe( "1.00ki" );
 
  38                         expect( byteSize_template( 1024 * 5 ) ).toBe( "5.00ki" );
 
  39                         expect( byteSize_template( 1024 * 55 ) ).toBe( "55.0ki" );
 
  40                         expect( byteSize_template( 1024 * 555 ) ).toBe( "555ki" );
 
  43                 it("should have the correct postfix", function() {
 
  44                         expect( byteSize_template( 3 * Math.pow( 1024, 1) ) ).toBe( "3.00ki" );
 
  45                         expect( byteSize_template( 3 * Math.pow( 1024, 2) ) ).toBe( "3.00Mi" );
 
  46                         expect( byteSize_template( 3 * Math.pow( 1024, 3) ) ).toBe( "3.00Gi" );
 
  47                         expect( byteSize_template( 3 * Math.pow( 1024, 4) ) ).toBe( "3.00Ti" );
 
  48                         expect( byteSize_template( 3 * Math.pow( 1024, 5) ) ).toBe( "3.00Pi" );
 
  49                         expect( byteSize_template( 3 * Math.pow( 1024, 6) ) ).toBe( "3.00Ei" );
 
  50                         expect( byteSize_template( 3 * Math.pow( 1024, 7) ) ).toBe( "3.00Zi" );
 
  51                         expect( byteSize_template( 3 * Math.pow( 1024, 8) ) ).toBe( "3.00Yi" );
 
  54                 it("should show an overflow for stupidly big numbers", function() {
 
  55                         expect( byteSize_template( 3 * Math.pow( 1024, 10) ) ).toBe( "3.00..E" );
 
  59         describe("count_template()", function() {
 
  60                 var count_template = window.app.ut.count_template;
 
  62                 it("should not postfix and not decimal for number less than 1000", function() {
 
  63                         expect( count_template( 0 ) ).toBe( "0" );
 
  64                         expect( count_template( 1 ) ).toBe( "1" );
 
  65                         expect( count_template( 10 ) ).toBe( "10" );
 
  66                         expect( count_template( 100 ) ).toBe( "100" );
 
  67                         expect( count_template( 999 ) ).toBe( "999" );
 
  70                 it("should always have three significant digits", function() {
 
  71                         expect( count_template( 1000  ) ).toBe( "1.00k" );
 
  72                         expect( count_template( 1005  ) ).toBe( "1.00k" );
 
  73                         expect( count_template( 1055  ) ).toBe( "1.05k" );
 
  74                         expect( count_template( 1000 * 5 ) ).toBe( "5.00k" );
 
  75                         expect( count_template( 1000 * 55 ) ).toBe( "55.0k" );
 
  76                         expect( count_template( 1000 * 555 ) ).toBe( "555k" );
 
  79                 it("should have the correct postfix", function() {
 
  80                         expect( count_template( 3 * Math.pow( 1000, 1) ) ).toBe( "3.00k" );
 
  81                         expect( count_template( 3 * Math.pow( 1000, 2) ) ).toBe( "3.00M" );
 
  82                         expect( count_template( 3 * Math.pow( 1000, 3) ) ).toBe( "3.00G" );
 
  83                         expect( count_template( 3 * Math.pow( 1000, 4) ) ).toBe( "3.00T" );
 
  84                         expect( count_template( 3 * Math.pow( 1000, 5) ) ).toBe( "3.00P" );
 
  85                         expect( count_template( 3 * Math.pow( 1000, 6) ) ).toBe( "3.00E" );
 
  86                         expect( count_template( 3 * Math.pow( 1000, 7) ) ).toBe( "3.00Z" );
 
  87                         expect( count_template( 3 * Math.pow( 1000, 8) ) ).toBe( "3.00Y" );
 
  90                 it("should show an overflow for stupidly big numbers", function() {
 
  91                         expect( count_template( 3 * Math.pow( 1000, 10) ) ).toBe( "3.00..E" );