#69 : Code cleanup

This commit is contained in:
Vadim
2021-09-13 22:41:36 +03:00
parent 7266566d54
commit 6108dbf910
4 changed files with 376 additions and 133 deletions

View File

@@ -73,8 +73,7 @@ describe('getIndexesOfPagesWithoutClonesInScroll', () => {
describe('getAdjacentIndexes', () => { describe('getAdjacentIndexes', () => {
it('returns indexes as expected if it is infinite', () => { it('returns indexes as expected if it is infinite', () => {
const testCases = [ const testCases = [{
{
pageIndex: 0, pageIndex: 0,
pagesCount: 2, pagesCount: 2,
particlesCount: 4, particlesCount: 4,
@@ -84,8 +83,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1], pageIndexes: [0, 1],
particleIndexes: [0, 1, 2, 3], particleIndexes: [0, 1, 2, 3],
}, },
}, }, {
{
pageIndex: -5, pageIndex: -5,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -95,8 +93,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1, 4], pageIndexes: [0, 1, 4],
particleIndexes: [0, 1, 2, 3, 8, 9], particleIndexes: [0, 1, 2, 3, 8, 9],
}, },
}, }, {
{
pageIndex: 0, pageIndex: 0,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -106,8 +103,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1, 4], pageIndexes: [0, 1, 4],
particleIndexes: [0, 1, 2, 3, 8, 9], particleIndexes: [0, 1, 2, 3, 8, 9],
}, },
}, }, {
{
pageIndex: 2, pageIndex: 2,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -117,8 +113,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1, 2, 3, 4], pageIndexes: [0, 1, 2, 3, 4],
particleIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], particleIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
}, },
}, }, {
{
pageIndex: 4, pageIndex: 4,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -128,8 +123,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 3, 4], pageIndexes: [0, 3, 4],
particleIndexes: [0, 1, 6, 7, 8, 9], particleIndexes: [0, 1, 6, 7, 8, 9],
}, },
}, }, {
{
pageIndex: 15, pageIndex: 15,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -139,8 +133,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 3, 4], pageIndexes: [0, 3, 4],
particleIndexes: [0, 1, 6, 7, 8, 9], particleIndexes: [0, 1, 6, 7, 8, 9],
}, },
}, }]
]
testCases.forEach(({ testCases.forEach(({
pageIndex, pageIndex,
pagesCount, pagesCount,
@@ -161,8 +154,7 @@ describe('getAdjacentIndexes', () => {
}) })
it('returns indexes as expected if it is not infinite', () => { it('returns indexes as expected if it is not infinite', () => {
const testCases = [ const testCases = [{
{
pageIndex: 0, pageIndex: 0,
pagesCount: 2, pagesCount: 2,
particlesCount: 4, particlesCount: 4,
@@ -172,8 +164,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1], pageIndexes: [0, 1],
particleIndexes: [0, 1, 2, 3], particleIndexes: [0, 1, 2, 3],
}, },
}, }, {
{
pageIndex: -5, pageIndex: -5,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -183,8 +174,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1, 4], pageIndexes: [0, 1, 4],
particleIndexes: [0, 1, 2, 3, 8, 9], particleIndexes: [0, 1, 2, 3, 8, 9],
}, },
}, }, {
{
pageIndex: 0, pageIndex: 0,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -194,8 +184,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1, 4], pageIndexes: [0, 1, 4],
particleIndexes: [0, 1, 2, 3, 8, 9], particleIndexes: [0, 1, 2, 3, 8, 9],
}, },
}, }, {
{
pageIndex: 2, pageIndex: 2,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -205,8 +194,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 1, 2, 3, 4], pageIndexes: [0, 1, 2, 3, 4],
particleIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], particleIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
}, },
}, }, {
{
pageIndex: 4, pageIndex: 4,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -216,8 +204,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 3, 4], pageIndexes: [0, 3, 4],
particleIndexes: [0, 1, 6, 7, 8, 9], particleIndexes: [0, 1, 6, 7, 8, 9],
}, },
}, }, {
{
pageIndex: 15, pageIndex: 15,
pagesCount: 5, pagesCount: 5,
particlesCount: 10, particlesCount: 10,
@@ -227,8 +214,7 @@ describe('getAdjacentIndexes', () => {
pageIndexes: [0, 3, 4], pageIndexes: [0, 3, 4],
particleIndexes: [0, 1, 6, 7, 8, 9], particleIndexes: [0, 1, 6, 7, 8, 9],
}, },
}, }]
]
testCases.forEach(({ testCases.forEach(({
pageIndex, pageIndex,
pagesCount, pagesCount,

View File

@@ -2,7 +2,6 @@ import {
getValueInRange, getValueInRange,
} from './math' } from './math'
// getCurrentPageIndexByCurrentParticleIndex // getCurrentPageIndexByCurrentParticleIndex
export function _getCurrentPageIndexByCurrentParticleIndexInfinite({ export function _getCurrentPageIndexByCurrentParticleIndexInfinite({

View File

@@ -120,42 +120,42 @@ describe('getPartialPageSize', () => {
}) })
describe('_getCurrentPageIndexByCurrentParticleIndexInfinite', () => { describe('_getCurrentPageIndexByCurrentParticleIndexInfinite', () => {
it('returns result as expected if particlesCount: 12; clonesCountHead: 2; clonesCountTotal: 5; particlesToScroll: 2 (particlesToShow: 3)', () => { it('returns result as expected if particlesCount: 13; clonesCountHead: 2; clonesCountTotal: 5; particlesToScroll: 2 (particlesToShow: 3)', () => {
const testCases = [{ const testCases = [{
particlesCount: 12, particlesCount: 13,
clonesCountHead: 2, clonesCountHead: 2,
clonesCountTotal: 5, clonesCountTotal: 5,
particlesToScroll: 2, particlesToScroll: 2,
currentParticleIndex: 0, currentParticleIndex: 0,
expected: 3, expected: 3,
}, { }, {
particlesCount: 12, particlesCount: 13,
clonesCountHead: 2, clonesCountHead: 2,
clonesCountTotal: 5, clonesCountTotal: 5,
particlesToScroll: 2, particlesToScroll: 2,
currentParticleIndex: 2, currentParticleIndex: 2,
expected: 0, expected: 0,
}, { }, {
particlesCount: 12, particlesCount: 13,
clonesCountHead: 2, clonesCountHead: 2,
clonesCountTotal: 5, clonesCountTotal: 5,
particlesToScroll: 2, particlesToScroll: 2,
currentParticleIndex: 4, currentParticleIndex: 4,
expected: 1, expected: 1,
}, { }, {
particlesCount: 12, particlesCount: 13,
clonesCountHead: 2, clonesCountHead: 2,
clonesCountTotal: 5, clonesCountTotal: 5,
particlesToScroll: 2, particlesToScroll: 2,
currentParticleIndex: 8, currentParticleIndex: 8,
expected: 3, expected: 3,
}, { }, {
particlesCount: 12, particlesCount: 13,
clonesCountHead: 2, clonesCountHead: 2,
clonesCountTotal: 5, clonesCountTotal: 5,
particlesToScroll: 2, particlesToScroll: 2,
currentParticleIndex: 10, currentParticleIndex: 10,
expected: 0, expected: 4,
}] }]
testCases.forEach(({ testCases.forEach(({
@@ -488,3 +488,261 @@ describe('_getPagesCountByParticlesCountLimited', () => {
}) })
}) })
}) })
describe('_getParticleIndexByPageIndexInfinite', () => {
it('returns result as expected if particlesCount: 11; clonesCountHead: 2; clonesCountTail: 3; particlesToScroll: 2 (particlesToShow: 3)', () => {
const testCases = [{
pageIndex: 0,
clonesCountHead: 1,
clonesCountTail: 3,
particlesToScroll: 2,
particlesCount: 11,
expected: 1,
}, {
pageIndex: 1,
clonesCountHead: 1,
clonesCountTail: 3,
particlesToScroll: 2,
particlesCount: 11,
expected: 3,
}, {
pageIndex: 2,
clonesCountHead: 1,
clonesCountTail: 3,
particlesToScroll: 2,
particlesCount: 11,
expected: 5,
}, {
pageIndex: 3,
clonesCountHead: 1,
clonesCountTail: 3,
particlesToScroll: 2,
particlesCount: 11,
expected: 7,
}]
testCases.forEach(({
pageIndex,
clonesCountHead,
clonesCountTail,
particlesToScroll,
particlesCount,
expected,
}) => {
expect(_getParticleIndexByPageIndexInfinite({
pageIndex,
clonesCountHead,
clonesCountTail,
particlesToScroll,
particlesCount,
})).toBe(expected)
})
})
it('returns result as expected if particlesCount: 10; clonesCountHead: 1; clonesCountTail: 2; particlesToScroll: 2 (particlesToShow: 2)', () => {
const testCases = [{
pageIndex: 0,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 2,
particlesCount: 10,
expected: 1,
}, {
pageIndex: 1,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 2,
particlesCount: 10,
expected: 3,
}, {
pageIndex: 2,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 2,
particlesCount: 10,
expected: 5,
}, {
pageIndex: 3,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 2,
particlesCount: 10,
expected: 7,
}]
testCases.forEach(({
pageIndex,
clonesCountHead,
clonesCountTail,
particlesToScroll,
particlesCount,
expected,
}) => {
expect(_getParticleIndexByPageIndexInfinite({
pageIndex,
clonesCountHead,
clonesCountTail,
particlesToScroll,
particlesCount,
})).toBe(expected)
})
})
it('returns result as expected if particlesCount: 10; clonesCountHead: 1; clonesCountTail: 2; particlesToScroll: 3 (particlesToShow: 2)', () => {
const testCases = [{
pageIndex: 0,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 3,
particlesCount: 10,
expected: 1,
}, {
pageIndex: 1,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 3,
particlesCount: 10,
expected: 4,
}, {
pageIndex: 2,
clonesCountHead: 1,
clonesCountTail: 2,
particlesToScroll: 3,
particlesCount: 10,
expected: 7,
}]
testCases.forEach(({
pageIndex,
clonesCountHead,
clonesCountTail,
particlesToScroll,
particlesCount,
expected,
}) => {
expect(_getParticleIndexByPageIndexInfinite({
pageIndex,
clonesCountHead,
clonesCountTail,
particlesToScroll,
particlesCount,
})).toBe(expected)
})
})
})
describe('_getParticleIndexByPageIndexLimited', () => {
it('returns result as expected if particlesCount: 6; particlesToScroll: 2; particlesToShow: 3', () => {
const testCases = [{
pageIndex: 0,
particlesToScroll: 2,
particlesCount: 6,
particlesToShow: 3,
expected: 0,
}, {
pageIndex: 1,
particlesToScroll: 2,
particlesCount: 6,
particlesToShow: 3,
expected: 2,
}, {
pageIndex: 2,
particlesToScroll: 2,
particlesCount: 6,
particlesToShow: 3,
expected: 3,
}]
testCases.forEach(({
pageIndex,
particlesToScroll,
particlesCount,
particlesToShow,
expected,
}) => {
expect(_getParticleIndexByPageIndexLimited({
pageIndex,
particlesToScroll,
particlesCount,
particlesToShow,
particlesCount,
})).toBe(expected)
})
})
it('returns result as expected if particlesCount: 6; particlesToScroll: 2; particlesToShow: 2', () => {
const testCases = [{
pageIndex: 0,
particlesToScroll: 2,
particlesCount: 6,
particlesToShow: 2,
expected: 0,
}, {
pageIndex: 1,
particlesToScroll: 2,
particlesCount: 6,
particlesToShow: 2,
expected: 2,
}, {
pageIndex: 2,
particlesToScroll: 2,
particlesCount: 6,
particlesToShow: 2,
expected: 4,
}]
testCases.forEach(({
pageIndex,
particlesToScroll,
particlesCount,
particlesToShow,
expected,
}) => {
expect(_getParticleIndexByPageIndexLimited({
pageIndex,
particlesToScroll,
particlesCount,
particlesToShow,
particlesCount,
})).toBe(expected)
})
})
it('returns result as expected if particlesCount: 6; particlesToScroll: 3; particlesToShow: 2', () => {
const testCases = [{
pageIndex: 0,
particlesToScroll: 3,
particlesCount: 6,
particlesToShow: 2,
expected: 0,
}, {
pageIndex: 1,
particlesToScroll: 3,
particlesCount: 6,
particlesToShow: 2,
expected: 3,
}, {
pageIndex: 2,
particlesToScroll: 3,
particlesCount: 6,
particlesToShow: 2,
expected: 4,
}]
testCases.forEach(({
pageIndex,
particlesToScroll,
particlesCount,
particlesToShow,
expected,
}) => {
expect(_getParticleIndexByPageIndexLimited({
pageIndex,
particlesToScroll,
particlesCount,
particlesToShow,
particlesCount,
})).toBe(expected)
})
})
})