mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 07:29:47 +08:00

* fixes: #{} * fixes : ISSUE#795 * Fixed ISSUE:795 * Fixed : ISSUE:795 * Fixed ISSUE : 795 * Fixed ISSUE : 795
23 lines
651 B
JavaScript
23 lines
651 B
JavaScript
import { FenwickTree } from '../FenwickTree'
|
|
|
|
describe('Fenwick Tree Implementation', () => {
|
|
const fenwickArray = new Array(1000)
|
|
const array = [3, 2, 0, 6, 5, -1, 2]
|
|
const length = array.length
|
|
|
|
const fenwickTree = new FenwickTree(fenwickArray, array, length)
|
|
|
|
it('Fenwick Tree - Prefix sum of array', () => {
|
|
const prefixSum = fenwickTree.getPrefixSum(fenwickArray, 6)
|
|
expect(prefixSum).toBe(23)
|
|
})
|
|
|
|
array[2] += 6
|
|
fenwickTree.update(fenwickArray, length, 2, 6)
|
|
|
|
it('Fenwick Tree - Prefix sum of Updated array', () => {
|
|
const prefixSum = fenwickTree.getPrefixSum(fenwickArray, 6)
|
|
expect(prefixSum).toBe(23)
|
|
})
|
|
})
|