Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sweep: Add an empty test file called FoldIndex.test.ts #10

Open
utdemir opened this issue Aug 6, 2023 · 1 comment · May be fixed by #11
Open

sweep: Add an empty test file called FoldIndex.test.ts #10

utdemir opened this issue Aug 6, 2023 · 1 comment · May be fixed by #11
Labels
sweep Assigns Sweep to an issue or pull request.

Comments

@utdemir
Copy link
Owner

utdemir commented Aug 6, 2023

  • Create a new test file called FoldIndex.test.ts.
  • Make sure to add necessary imports to make it compile, You can look at HashIndex.test.ts for reference.
  • Just add one place holder tests that always passes.
@sweep-ai sweep-ai bot added the sweep Assigns Sweep to an issue or pull request. label Aug 6, 2023
@sweep-ai
Copy link
Contributor

sweep-ai bot commented Aug 6, 2023

Here's the PR! #11.

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 3 GPT-4 tickets left. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

https://github.com/utdemir/composable-indexes/blob/fc5af29f2ede21be73acb39f6b64c4b3c77830f6/core/src/indexes/HashIndex.test.ts#L1-L61

img {
max-width: 100%;
}
.tsd-anchor-icon {
display: inline-flex;
align-items: center;
margin-left: 0.5rem;
vertical-align: middle;
color: var(--color-text);
}
.tsd-anchor-icon svg {
width: 1em;
height: 1em;
visibility: hidden;
}
.tsd-anchor-link:hover > .tsd-anchor-icon svg {
visibility: visible;
}
.deprecated {
text-decoration: line-through;
}
.warning {
padding: 1rem;
color: var(--color-warning-text);
background: var(--color-background-warning);
}
.tsd-kind-project {
color: var(--color-ts-project);
}
.tsd-kind-module {
color: var(--color-ts-module);
}
.tsd-kind-namespace {
color: var(--color-ts-namespace);
}
.tsd-kind-enum {
color: var(--color-ts-enum);
}
.tsd-kind-enum-member {
color: var(--color-ts-enum-member);
}
.tsd-kind-variable {
color: var(--color-ts-variable);
}
.tsd-kind-function {
color: var(--color-ts-function);
}
.tsd-kind-class {
color: var(--color-ts-class);
}
.tsd-kind-interface {
color: var(--color-ts-interface);
}
.tsd-kind-constructor {
color: var(--color-ts-constructor);
}
.tsd-kind-property {
color: var(--color-ts-property);
}
.tsd-kind-method {
color: var(--color-ts-method);
}
.tsd-kind-call-signature {
color: var(--color-ts-call-signature);
}
.tsd-kind-index-signature {
color: var(--color-ts-index-signature);
}
.tsd-kind-constructor-signature {
color: var(--color-ts-constructor-signature);

import { strict as assert } from "node:assert";
import test from "node:test";
import { Collection } from "./Collection";
import { sumIndex, btreeIndex } from "../indexes";
import Long from "long";
import { MockIndex } from "../test_util/MockIndex";
import { UpdateType } from "./Update";
import { Id, Item } from "./simple_types";
test("Collection", async (t) => {
await test("simple", () => {
const c = new Collection();
const ix = c.add(12);
assert.strictEqual(c.get(ix), 12);
});
await test("delete", () => {
const c = new Collection();
const ix = c.add(12);
assert.strictEqual(c.delete(ix), 12);
assert.strictEqual(c.get(ix), undefined);
});
await test("update", () => {
const c = new Collection();
const ix = c.add(12);
c.set(ix, 13);
assert.strictEqual(c.get(ix), 13);
});
await test("delete non existent", () => {
const c = new Collection<number>();
const ix = c.add(12);
assert.strictEqual(c.delete(ix), 12);
assert.strictEqual(c.delete(ix), undefined);
});
await test("simple index", () => {
const c = new Collection<number>();
const ix1 = c.add(1);
const sum = c.registerIndex(sumIndex());
assert.strictEqual(sum.value(), 1);
c.add(2);
assert.strictEqual(sum.value(), 3);
c.delete(ix1);
assert.strictEqual(sum.value(), 2);
const ix2 = c.add(5);
assert.strictEqual(sum.value(), 7);
c.set(ix2, 6);
assert.strictEqual(sum.value(), 8);
});
await test("multiple indexes", () => {
const c = new Collection<number>();
const ix1 = c.registerIndex(sumIndex());
const ix2 = c.registerIndex(btreeIndex());
c.add(1);
c.add(2);
c.add(3);
const maxId = c.add(10);
c.add(9);
c.add(8);
assert.deepEqual(ix1.value(), 33);
assert.deepEqual(ix2.max1(), new Item(maxId, 10));
});
await test("operations: add", () => {
const c = new Collection<number>();
const ix = c.registerIndex(MockIndex.create());
c.add(1);
assert.deepEqual(ix.collectedUpdates, [
{ type: UpdateType.ADD, id: Id.fromLong(Long.fromNumber(1, true)), value: 1 },
]);
c.add(2);
assert.deepEqual(ix.collectedUpdates, [
{ type: UpdateType.ADD, id: Id.fromLong(Long.fromNumber(1, true)), value: 1 },
{ type: UpdateType.ADD, id: Id.fromLong(Long.fromNumber(2, true)), value: 2 },
]);
});
await test("operations: update", () => {
const c = new Collection<number>();
const ix = c.registerIndex(MockIndex.create());
const id = Id.fromLong(Long.fromNumber(1, true));
c.set(id, 1);
c.set(id, 2);
assert.deepEqual(ix.collectedUpdates, [
{ type: UpdateType.ADD, id, value: 1 },
{ type: UpdateType.UPDATE, id, oldValue: 1, newValue: 2 },
]);
});
await test("operations: delete", () => {
const c = new Collection<number>();
const ix = c.registerIndex(MockIndex.create());
const id = c.add(1);
c.delete(id);
assert.deepEqual(ix.collectedUpdates, [
{ type: UpdateType.ADD, id, value: 1 },
{ type: UpdateType.DELETE, id, oldValue: 1 },
]);
// Deleting a non-existent item doesn't change anything
c.delete(Id.fromLong(Long.fromNumber(666)));
assert.deepEqual(ix.collectedUpdates, [
{ type: UpdateType.ADD, id, value: 1 },
{ type: UpdateType.DELETE, id, oldValue: 1 },
]);
});
});

import test from "node:test";
import { BTreeIndex, btreeIndex } from "./BTreeIndex";
import fc from "fast-check";
import { propIndexAgainstReference } from "../test_util/reference";
import { testProps } from "../test_util/invariants";
import { Item } from "../core/simple_types";
test("BTreeIndex", async (t) => {
await test("ref.eq", () => {
fc.assert(
propIndexAgainstReference<
number,
BTreeIndex<number, number>,
Item<number>[]
>({
valueGen: fc.integer({ min: 0, max: 5 }),
index: btreeIndex(),
value: (ix) => ix.eq(1).sort((a, b) => a.id.compare(b.id)),
reference: (arr) =>
arr.filter((it) => it.value === 1).sort((a, b) => a.id.compare(b.id)),
}),
{
numRuns: 10000,
}
);
});
await test("ref.max", () => {
fc.assert(
propIndexAgainstReference<
number,
BTreeIndex<number, number>,
Item<number>[]
>({
valueGen: fc.integer({ min: 0, max: 5 }),
index: btreeIndex(),
value: (ix) => ix.max().sort((a, b) => a.id.compare(b.id)),
reference: (arr) => {
// Find the maximum value
const max = Math.max(...arr.map((it) => it.value));
// Find all items with that value
return arr
.filter((it) => it.value === max)
.sort((a, b) => a.id.compare(b.id));
},
}),
{
numRuns: 10000,
}
);
});
await test("ref.range", () => {
fc.assert(
propIndexAgainstReference<
number,
BTreeIndex<number, number>,
number[]
>({
valueGen: fc.integer({ min: 0, max: 5 }),
index: btreeIndex(),
value: (ix) => ix.range({ minValue: 1, maxValue: 3 }).map(i => i.value).sort(),
reference: (arr) => {
return arr
.map((it) => it.value)
.filter((v) => v >= 1 && v <= 3)
.sort();
},
}),
{
numRuns: 10000,
}
);
});
const witnesses = {
eq: (ix: BTreeIndex<number, number>) =>
ix
.eq(1)
.map((v) => v.value)
.sort(),
countDistinct: (ix: BTreeIndex<number, number>) => ix.countDistinct(),
max: (ix: BTreeIndex<number, number>) => {
const ret = ix.max();
return [ret[0]?.value, ret.length];
},
min: (ix: BTreeIndex<number, number>) => {
const ret = ix.min();
return [ret[0]?.value, ret.length];
},
range: (ix: BTreeIndex<number, number>) => {
const ret = ix.range({
minValue: 1,
maxValue: 3
});
return ret.map(it => it.value).sort();
},
};
for (const [name, witness] of Object.entries(witnesses)) {
await test(`props.${name}`, async (t) => {
await testProps<number, BTreeIndex<number, number>, any>(t, {
valueGen: fc.integer(),
index: btreeIndex(),
witness,
});
});
}
});

https://github.com/utdemir/composable-indexes/blob/fc5af29f2ede21be73acb39f6b64c4b3c77830f6/docs/src/01 Tutorial.md#L13-L127

I also found the following external resources that might be helpful:

Summaries of links found in the content:


Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
core/src/indexes/FoldIndex.test.ts Create a new file named FoldIndex.test.ts in the core/src/indexes/ directory. Add necessary imports at the top of the file, similar to the ones in HashIndex.test.ts. Then, define a placeholder test that always passes. The test can be named "Placeholder Test" and can simply assert that true is true.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add empty test file called FoldIndex.test.ts
sweep/add-fold-index-test-file

Description

This PR adds a new test file called FoldIndex.test.ts to the core/src/indexes/ directory. The file includes the necessary imports to make it compile, similar to the HashIndex.test.ts file. Additionally, a placeholder test that always passes has been added to ensure the file is set up correctly.

Summary of Changes

  • Created a new test file FoldIndex.test.ts in the core/src/indexes/ directory.
  • Added necessary imports to make the file compile, based on the structure of HashIndex.test.ts.
  • Included a placeholder test that always passes to verify the setup of the file.

Please review and merge this PR. Thank you!


Step 4: ⌨️ Coding

I have finished coding the issue. I am now reviewing it for completeness.


Step 5: 🔁 Code Review

Success! 🚀


To recreate the pull request, leave a comment prefixed with "sweep:" or edit the issue.
Join Our Discord

@sweep-ai sweep-ai bot linked a pull request Aug 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Assigns Sweep to an issue or pull request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant