|
| 1 | +const Wavelength = require('./Wavelength').default; |
| 2 | + |
| 3 | + |
| 4 | +describe('Wavelength', () => { |
| 5 | + let wavelength = new Wavelength('300'); |
| 6 | + |
| 7 | + test('should throw error when initialized with out a frequency', () => { |
| 8 | + expect(() => { |
| 9 | + new Wavelength() |
| 10 | + }).toThrowError('Need a frequency to init a Wavelength'); |
| 11 | + }); |
| 12 | + |
| 13 | + |
| 14 | + test('should initialize with a wavelength and output as string', () => { |
| 15 | + expect(wavelength.toString()).toEqual("1.000"); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should initialize with a wavelength and output as float', () => { |
| 19 | + expect(wavelength.toFloat()).toEqual(1.0); |
| 20 | + }); |
| 21 | + |
| 22 | + test('should set precision to 1', () => { |
| 23 | + wavelength.setPrecision(1); |
| 24 | + expect(wavelength.toString()).toEqual("1"); |
| 25 | + wavelength.setPrecision(4); |
| 26 | + }); |
| 27 | + |
| 28 | + // meters tests |
| 29 | + test('should show full wavelength in meters as 1.000', () => { |
| 30 | + expect(wavelength.toString()).toEqual("1.000"); |
| 31 | + expect(wavelength.toFloat()).toEqual(1.000); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should show three quarters wavelength in meters as 0.7500', () => { |
| 35 | + wavelength.setPrecision(4); |
| 36 | + expect(wavelength.toThreeQuartersWavelength('m')).toEqual("0.7500"); |
| 37 | + expect(parseFloat(wavelength.toThreeQuartersWavelength('m'))).toEqual(0.7500); |
| 38 | + }); |
| 39 | + |
| 40 | + test('should show five eighths half wavelength in meters as 0.6250', () => { |
| 41 | + wavelength.setPrecision(4); |
| 42 | + expect(wavelength.toFiveEighthsWavelength('m')).toEqual("0.6250"); |
| 43 | + expect(parseFloat(wavelength.toFiveEighthsWavelength('m'))).toEqual(0.6250); |
| 44 | + }); |
| 45 | + |
| 46 | + test('should show one half wavelength in meters as 0.5000', () => { |
| 47 | + wavelength.setPrecision(4); |
| 48 | + expect(wavelength.toHalfWavelength('m')).toEqual("0.5000"); |
| 49 | + expect(parseFloat(wavelength.toHalfWavelength('m'))).toEqual(0.5000); |
| 50 | + }); |
| 51 | + |
| 52 | + test('should show one quarter wavelength in meters as 0.2500', () => { |
| 53 | + wavelength.setPrecision(4); |
| 54 | + expect(wavelength.toQuarterWavelength('m')).toEqual("0.2500"); |
| 55 | + expect(parseFloat(wavelength.toQuarterWavelength('m'))).toEqual(0.2500); |
| 56 | + }); |
| 57 | + |
| 58 | + // centimeters tests |
| 59 | + test('should show full wavelength in centimeters as 100.0', () => { |
| 60 | + expect(wavelength.toCentimeters()).toEqual("100.0"); |
| 61 | + expect(parseFloat(wavelength.toCentimeters())).toEqual(100); |
| 62 | + }); |
| 63 | + |
| 64 | + test('should show three quarters wavelength in centimeters as 75.00', () => { |
| 65 | + wavelength.setPrecision(4); |
| 66 | + expect(wavelength.toThreeQuartersWavelength('cm')).toEqual("75.00"); |
| 67 | + expect(parseFloat(wavelength.toThreeQuartersWavelength('cm'))).toEqual(75.00); |
| 68 | + }); |
| 69 | + |
| 70 | + test('should show five eighths half wavelength in centimeters as 62.50', () => { |
| 71 | + wavelength.setPrecision(4); |
| 72 | + expect(wavelength.toFiveEighthsWavelength('cm')).toEqual("62.50"); |
| 73 | + expect(parseFloat(wavelength.toFiveEighthsWavelength('cm'))).toEqual(62.50); |
| 74 | + }); |
| 75 | + |
| 76 | + test('should show one half wavelength in centimeters as 50.00', () => { |
| 77 | + wavelength.setPrecision(4); |
| 78 | + expect(wavelength.toHalfWavelength('cm')).toEqual("50.00"); |
| 79 | + expect(parseFloat(wavelength.toHalfWavelength('cm'))).toEqual(50.00); |
| 80 | + }); |
| 81 | + |
| 82 | + test('should show one quarter wavelength in centimeters as 25.00', () => { |
| 83 | + wavelength.setPrecision(4); |
| 84 | + expect(wavelength.toQuarterWavelength('cm')).toEqual("25.00"); |
| 85 | + expect(parseFloat(wavelength.toQuarterWavelength('cm'))).toEqual(25.00); |
| 86 | + }); |
| 87 | + |
| 88 | + // feet tests |
| 89 | + |
| 90 | + test('should show full wavelength in feet as 3.281', () => { |
| 91 | + wavelength.setPrecision(4); |
| 92 | + expect(wavelength.toFeet()).toEqual("3.281"); |
| 93 | + expect(parseFloat(wavelength.toFeet())).toEqual(3.281); |
| 94 | + }); |
| 95 | + |
| 96 | + test('should show three quarters wavelength in feet as 2.4611', () => { |
| 97 | + wavelength.setPrecision(4); |
| 98 | + expect(wavelength.toThreeQuartersWavelength('f')).toEqual("2.461"); |
| 99 | + expect(parseFloat(wavelength.toThreeQuartersWavelength('f'))).toEqual(2.461); |
| 100 | + }); |
| 101 | + |
| 102 | + test('should show five eighths half wavelength in feet as 2.051', () => { |
| 103 | + wavelength.setPrecision(4); |
| 104 | + expect(wavelength.toFiveEighthsWavelength('f')).toEqual("2.051"); |
| 105 | + expect(parseFloat(wavelength.toFiveEighthsWavelength('f'))).toEqual(2.051); |
| 106 | + }); |
| 107 | + |
| 108 | + test('should show one half wavelength in feet as 1.640', () => { |
| 109 | + wavelength.setPrecision(4); |
| 110 | + expect(wavelength.toHalfWavelength('f')).toEqual("1.640"); |
| 111 | + expect(parseFloat(wavelength.toHalfWavelength('f'))).toEqual(1.640); |
| 112 | + }); |
| 113 | + |
| 114 | + test('should show one quarter wavelength in feet as 0.8202', () => { |
| 115 | + wavelength.setPrecision(4); |
| 116 | + expect(wavelength.toQuarterWavelength('f')).toEqual("0.8202"); |
| 117 | + expect(parseFloat(wavelength.toQuarterWavelength('f'))).toEqual(0.8202); |
| 118 | + }); |
| 119 | + |
| 120 | + |
| 121 | + // inches tests |
| 122 | + |
| 123 | + test('should show full wavelength in inches as 39.37', () => { |
| 124 | + wavelength.setPrecision(4); |
| 125 | + expect(wavelength.toInches()).toEqual("39.37"); |
| 126 | + expect(parseFloat(wavelength.toInches())).toEqual(39.37); |
| 127 | + }); |
| 128 | + |
| 129 | + test('should show three quarters wavelength in feet as 29.53', () => { |
| 130 | + wavelength.setPrecision(4); |
| 131 | + expect(wavelength.toThreeQuartersWavelength('in')).toEqual("29.53"); |
| 132 | + expect(parseFloat(wavelength.toThreeQuartersWavelength('in'))).toEqual(29.53); |
| 133 | + }); |
| 134 | + |
| 135 | + test('should show five eighths half wavelength in feet as 24.61', () => { |
| 136 | + wavelength.setPrecision(4); |
| 137 | + expect(wavelength.toFiveEighthsWavelength('in')).toEqual("24.61"); |
| 138 | + expect(parseFloat(wavelength.toFiveEighthsWavelength('in'))).toEqual(24.61); |
| 139 | + }); |
| 140 | + |
| 141 | + test('should show one half wavelength in feet as 19.69', () => { |
| 142 | + wavelength.setPrecision(4); |
| 143 | + expect(wavelength.toHalfWavelength('in')).toEqual("19.69"); |
| 144 | + expect(parseFloat(wavelength.toHalfWavelength('in'))).toEqual(19.69); |
| 145 | + }); |
| 146 | + |
| 147 | + test('should show one quarter wavelength in feet as 9.843', () => { |
| 148 | + wavelength.setPrecision(4); |
| 149 | + expect(wavelength.toQuarterWavelength('in')).toEqual("9.843"); |
| 150 | + expect(parseFloat(wavelength.toQuarterWavelength('in'))).toEqual(9.843); |
| 151 | + }); |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + // test('if current is .5 and volts are 10 then resistance should be 20 and wattage should be 5', () => { |
| 157 | + // expect(OhmsLaw.calcWattsResistance(.5, 10)).toEqual({ |
| 158 | + // resistance: 20, |
| 159 | + // watts: 5 |
| 160 | + // }) |
| 161 | + // }); |
| 162 | + |
| 163 | +}); |
0 commit comments