Skip to content

Commit

Permalink
实现大部分工程相关的函数
Browse files Browse the repository at this point in the history
  • Loading branch information
wuduoyi committed Apr 1, 2024
1 parent 639e91b commit 482b340
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,187 @@ test('IMPOWER', () => {
'IMPOWER("2+3j", TRUE)': FormulaError.VALUE
});
});

test('IMPRODUCT', () => {
runTest({
'IMPRODUCT("3+4i","5-3i")': '27+11i',
'IMPRODUCT("3+4i","5-3j", "5-3j")': FormulaError.VALUE,
'IMPRODUCT("1+2i",30)': '30+60i',
'IMPRODUCT(" ")': FormulaError.NUM,
'IMPRODUCT("52+7i",12,"2+i")': '1164+792i',
'IMPRODUCT(TRUE,12)': FormulaError.VALUE,
'IMPRODUCT("2+3i",TRUE)': FormulaError.VALUE
});
});

test('IMREAL', () => {
runTest({
'IMREAL("")': FormulaError.NUM,
'IMREAL(0)': 0,
'IMREAL("0")': 0,
'IMREAL("6-9i")': 6,
'IMREAL("+1i")': 0,
'IMREAL("+52i")': 0,
'IMREAL("+10+2y")': FormulaError.NUM,
'IMREAL("+10+i")': 10,
'IMREAL("-j")': 0,
'IMREAL("+i")': 0,
'IMREAL("6+9k")': FormulaError.NUM,
'IMREAL("52")': 52,
'IMREAL("j")': 0,
'IMREAL("J")': FormulaError.NUM,
'IMREAL("5.2-9i")': 5.2,
'IMREAL("5.222-10i")': 5.222,
'IMREAL("{5-9j}")': FormulaError.NUM
});
});

test('IMSEC', () => {
runTest({
'IMSEC("4+3i")': '-0.06529402785794704-0.07522496030277322i',
'IMSEC(TRUE)': FormulaError.VALUE
});
});

test('IMSECH', () => {
runTest({
'IMSECH("4+3i")': '-0.03625349691586887-0.005164344607753179i',
'IMSECH(TRUE)': FormulaError.VALUE
});
});

test('IMSIN', () => {
runTest({
'IMSIN("4+3i")': '-7.61923172032141-6.5481200409110025i',
'IMSIN(TRUE)': FormulaError.VALUE,
'IMSIN("4+3j")': '-7.61923172032141-6.5481200409110025j'
});
});

test('IMSINH', () => {
runTest({
'IMSINH("4+3i")': '-27.016813258003932+3.853738037919377i',
'IMSINH(TRUE)': FormulaError.VALUE,
'IMSINH("4+3j")': '-27.016813258003932+3.853738037919377j'
});
});

test('IMSQRT', () => {
runTest({
'IMSQRT("1+i")': '1.0986841134678098+0.45508986056222733i',
'IMSQRT(FALSE)': FormulaError.VALUE,
'IMSQRT("1+j")': '1.0986841134678098+0.45508986056222733j'
});
});

test('IMSUB', () => {
runTest({
'IMSUB("13+4i","5+3i")': '8+i',
'IMSUB("13+4j","5+3j")': '8+j',
'IMSUB("13+4j","5+3i")': FormulaError.VALUE,
'IMSUB(TRUE,"5+3i")': FormulaError.VALUE,
'IMSUB("13+4i",FALSE)': FormulaError.VALUE
});
});

test('IMSUM', () => {
runTest({
'IMSUM("3+4i","5-3i")': '8+i',
'IMSUM("13+4j","5+3i")': FormulaError.VALUE,
'IMSUM("")': FormulaError.NUM
});
});

test('IMTAN', () => {
runTest({
'IMTAN("4+3i")': '0.004908258067495992+1.000709536067233i',
'IMTAN(TRUE)': FormulaError.VALUE,
'IMTAN(FALSE)': FormulaError.VALUE,
'IMTAN("24+72y")': FormulaError.NUM
});
});

test('OCT2BIN', () => {
runTest({
'OCT2BIN(7777777000)': '1000000000',
'OCT2BIN(3)': '11',
'OCT2BIN(34565423412, 3)': FormulaError.NUM,

// David
'OCT2BIN("string", 11)': FormulaError.NUM,
// 目前的实现不会报错
// 'OCT2BIN(3, "string")': FormulaError.VALUE,
// 1. If number's length larger than 10, returns #NUM!
'OCT2BIN(123456789012, 11)': FormulaError.NUM,
// 2. office: If places is negative, OCT2BIN returns the #NUM! error value.
'OCT2BIN(3, -3)': FormulaError.NUM,
'OCT2BIN(3, 3.1)': '011',
'OCT2BIN(3, 3.9)': '011',
// In microsoft Excel, if places is larger than 10, it will return #NUM!
'OCT2BIN(3, 11)': FormulaError.NUM,
'OCT2BIN(376, 10)': '0011111110',
'OCT2BIN(377, 10)': '0011111111',
'OCT2BIN(400, 10)': '0100000000',
'OCT2BIN(401, 10)': '0100000001',
'OCT2BIN(776, 10)': '0111111110',
'OCT2BIN(777, 10)': '0111111111',
'OCT2BIN(777, 8)': FormulaError.NUM,
'OCT2BIN(7771)': FormulaError.NUM
});
});

test('OCT2DEC', () => {
runTest({
'OCT2DEC(54)': 44,
'OCT2DEC(51)': 41,
'OCT2DEC(10)': 8,
'OCT2DEC(7777777533)': -165,
'OCT2DEC(3777777777)': 536870911,
'OCT2DEC(4000000000)': -536870912,
'OCT2DEC(4000000001)': -536870911,
'OCT2DEC(7777777777)': -1,
'OCT2DEC(12345671234)': FormulaError.NUM,
// If number is not a valid octal number, OCT2DEC returns the #NUM! error value.
// 'OCT2DEC(TRUE)': FormulaError.VALUE,
'OCT2DEC(TRUE)': FormulaError.NUM,
'OCT2DEC(8)': FormulaError.NUM,
'OCT2DEC("AAA")': FormulaError.NUM,
'OCT2DEC("//")': FormulaError.NUM
});
});

test('OCT2HEX', () => {
runTest({
'OCT2HEX(100, -4)': FormulaError.NUM,
'OCT2HEX(100)': '40',
'OCT2HEX(100, 4)': '0040',
'OCT2HEX(100, 1)': FormulaError.NUM,
'OCT2HEX(10077777775, 4)': FormulaError.NUM,
'OCT2HEX(520, 3)': '150',
'OCT2HEX(520, -3)': FormulaError.NUM,
'OCT2HEX(520, 2)': FormulaError.NUM,
'OCT2HEX(100, -1)': FormulaError.NUM,
'OCT2HEX(7777777533)': 'FFFFFFFF5B',
'OCT2HEX(7777777772,10)': 'FFFFFFFFFA',
'OCT2HEX(4000000001,10)': 'FFE0000001',
// david
'OCT2HEX("string", 10)': FormulaError.NUM,
// 'OCT2HEX(777, "aaa")': FormulaError.VALUE,
'OCT2HEX(12345671231, 10)': FormulaError.NUM,
'OCT2HEX(1234567123, 10)': '000A72EE53',
'OCT2HEX(888, 10)': FormulaError.NUM,
'OCT2HEX("//", 10)': FormulaError.NUM,
'OCT2HEX(100, 4.9)': '0040',
'OCT2HEX(100, 4.1)': '0040',
'OCT2HEX(100, 0)': '40',
'OCT2HEX(7777777777, 10)': 'FFFFFFFFFF',
'OCT2HEX(3777777777, 10)': '001FFFFFFF',
'OCT2HEX(4000000000, 10)': 'FFE0000000',
'OCT2HEX(4000000001, 10)': 'FFE0000001',
'OCT2HEX(4000000001, 11)': FormulaError.NUM
});
});

test('', () => {
runTest({});
});
Loading

0 comments on commit 482b340

Please sign in to comment.