{"size": 1666, "ext": "js", "max_stars_repo_path": "packages/rdt/__tests__/iheap.js", "max_stars_repo_name": "basa507/swarm", "max_stars_repo_stars_event_min_datetime": "2015-01-01T14:01:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-18T13:11:42.000Z", "max_issues_repo_path": "packages/rdt/__tests__/iheap.js", "max_issues_repo_name": "basa507/swarm", "max_issues_repo_issues_event_min_datetime": "2015-01-06T17:46:30.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-29T07:30:57.000Z", "max_forks_repo_path": "packages/rdt/__tests__/iheap.js", "max_forks_repo_name": "basa507/swarm", "max_forks_repo_forks_event_min_datetime": "2015-01-04T19:20:53.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-12T20:25:14.000Z"}
{"max_stars_count": 1918, "max_issues_count": 57, "max_forks_count": 117, "avg_line_length": 26.8709677419, "max_line_length": 88, "alphanum_fraction": 0.6074429772}
// @flow

import IHeap, {eventComparator, eventComparatorDesc, refComparator} from '../src/iheap';
import Op, {Batch, ZERO, Frame} from '@swarm/ron';

test('IHeap put frame', () => {
  const frameA = "*lww#test@time1-orig:number=1@(2:string'2'";
  const frameB = "*lww#test@time3-orig:number=3@(4:string'4'";
  const frameC = "*lww#test@time1-orig:number=1@(2:string'2'@(3:number=3@(4:string'4'";

  const heap = new IHeap(eventComparator);

  heap.put(new Frame(frameA));
  heap.put(new Frame(frameB));

  expect(heap.frame().toString()).toBe(frameC);
});

test('IHeap op', () => {
  const frames = new Batch(
    new Frame("*lww#test@time1-orig:number=1@(2:string'2'"),
    new Frame("*lww#test@time3-orig:number=3@(4:string'4'"),
    new Frame("*lww#test@time2-orig:number=2@(2:string'2'@(3:number=3@(4:string'4'"),
  );

  const heap = new IHeap(refComparator);
  heap.put(frames);
  // $FlowFixMe
  const loc = heap.current().uuid(3);
  let count = 0;

  while (
    // $FlowFixMe
    heap
      .current()
      .uuid(3)
      .eq(loc)
  ) {
    count++;
    heap.next();
  }
  expect(count).toBe(3);
});

test('IHeap merge', () => {
  const frameA = "*rga#test@1:0'A'@2'B'"; //  D E A C B
  const frameB = "*rga#test@1:0'A'@3'C'";
  const frameC = "*rga#test@4:0'D'@5'E'";
  const frameR = "*rga#test@4'D'@5'E'@1'A'@3'C'@2'B'";
  const heap = new IHeap(eventComparatorDesc, refComparator);
  heap.put(new Frame(frameA));
  heap.put(new Frame(frameB));
  heap.put(new Frame(frameC));
  const res = new Frame();
  while (!heap.eof()) {
    const op = heap.current() || ZERO;
    res.push(op);
    heap.nextPrim();
  }
  expect(res.toString()).toBe(frameR);
});
