privateFunctionTest.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Created by Tony on 2017/4/5.
  3. */
  4. var test = require('tape');
  5. var headerStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  6. test('test private 1', function(t){
  7. private_getCellIdxStr = function(idx, pre){
  8. var rst = 'A', prefix = '', tmpIdx = idx;
  9. if (tmpIdx >= 26) {
  10. var ti = Math.floor(tmpIdx / 26), tj = tmpIdx % 26;
  11. if (ti <= 26) {
  12. rst = pre + headerStr[ti - 1] + headerStr[tj];
  13. } else {
  14. rst = private_getCellIdxStr(ti, 'A' + pre) + headerStr[tj];
  15. }
  16. } else {
  17. rst = pre + headerStr[tmpIdx % 26];
  18. }
  19. return rst;
  20. };
  21. //t.equal(private_getCellIdxStr(0, ''), 'A');
  22. //t.equal(private_getCellIdxStr(25, ''), 'Z');
  23. //t.equal(private_getCellIdxStr(26, ''), 'AA');
  24. //t.equal(private_getCellIdxStr(27, ''), 'AB');
  25. //t.equal(private_getCellIdxStr(51, ''), 'AZ');
  26. //t.equal(private_getCellIdxStr(52, ''), 'BA');
  27. //t.equal(private_getCellIdxStr(675, ''), 'YZ');
  28. //t.equal(private_getCellIdxStr(676, ''), 'ZA');
  29. //t.equal(private_getCellIdxStr(701, ''), 'ZZ');
  30. t.equal(private_getCellIdxStr(702, ''), 'AAA');
  31. t.end();
  32. })