Add richer types to graphDemoData (#146)
In preparation for using type info in the Graph apis, it is helpful to have richer type info in the graph demo data. Test plan: Check that the snapshot changes only consist of type changes, and that CI passes.
This commit is contained in:
parent
18ce9982d2
commit
c635034dab
|
@ -3,12 +3,12 @@
|
||||||
exports[`graph #Graph JSON functions should serialize a simple graph 1`] = `
|
exports[`graph #Graph JSON functions should serialize a simple graph 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"edges": Object {
|
"edges": Object {
|
||||||
"{\\"id\\":\\"crab-self-assessment\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"crab-self-assessment\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"SILLY\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "razorclaw_crab#2",
|
"id": "razorclaw_crab#2",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
"payload": Object {
|
"payload": Object {
|
||||||
"evaluation": "not effective at avoiding hero",
|
"evaluation": "not effective at avoiding hero",
|
||||||
|
@ -17,15 +17,15 @@ Object {
|
||||||
"id": "razorclaw_crab#2",
|
"id": "razorclaw_crab#2",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"hero_of_time#0@again_cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"hero_of_time#0@again_cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "hero_of_time#0",
|
"id": "hero_of_time#0",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "PC",
|
||||||
},
|
},
|
||||||
"payload": Object {
|
"payload": Object {
|
||||||
"crit": true,
|
"crit": true,
|
||||||
|
@ -35,15 +35,15 @@ Object {
|
||||||
"id": "seafood_fruit_mix#3",
|
"id": "seafood_fruit_mix#3",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"hero_of_time#0@cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"hero_of_time#0@cooks@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "hero_of_time#0",
|
"id": "hero_of_time#0",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "PC",
|
||||||
},
|
},
|
||||||
"payload": Object {
|
"payload": Object {
|
||||||
"crit": false,
|
"crit": false,
|
||||||
|
@ -52,96 +52,96 @@ Object {
|
||||||
"id": "seafood_fruit_mix#3",
|
"id": "seafood_fruit_mix#3",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"hero_of_time#0@eats@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"hero_of_time#0@eats@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "seafood_fruit_mix#3",
|
"id": "seafood_fruit_mix#3",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
"src": Object {
|
"src": Object {
|
||||||
"id": "hero_of_time#0",
|
"id": "hero_of_time#0",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "PC",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"hero_of_time#0@grabs@razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"hero_of_time#0@grabs@razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "hero_of_time#0",
|
"id": "hero_of_time#0",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "PC",
|
||||||
},
|
},
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
"src": Object {
|
"src": Object {
|
||||||
"id": "razorclaw_crab#2",
|
"id": "razorclaw_crab#2",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"hero_of_time#0@picks@mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"hero_of_time#0@picks@mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"ACTION\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "hero_of_time#0",
|
"id": "hero_of_time#0",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "PC",
|
||||||
},
|
},
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
"src": Object {
|
"src": Object {
|
||||||
"id": "mighty_bananas#1",
|
"id": "mighty_bananas#1",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"mighty_bananas#1@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"mighty_bananas#1@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"INGREDIENT\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "mighty_bananas#1",
|
"id": "mighty_bananas#1",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
"src": Object {
|
"src": Object {
|
||||||
"id": "seafood_fruit_mix#3",
|
"id": "seafood_fruit_mix#3",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"razorclaw_crab#2@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"razorclaw_crab#2@included_in@seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"INGREDIENT\\"}": Object {
|
||||||
"dst": Object {
|
"dst": Object {
|
||||||
"id": "razorclaw_crab#2",
|
"id": "razorclaw_crab#2",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
"src": Object {
|
"src": Object {
|
||||||
"id": "seafood_fruit_mix#3",
|
"id": "seafood_fruit_mix#3",
|
||||||
"pluginName": "hill_cooking_pot",
|
"pluginName": "hill_cooking_pot",
|
||||||
"repositoryName": "sourcecred/eventide",
|
"repositoryName": "sourcecred/eventide",
|
||||||
"type": "demoType",
|
"type": "FOOD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"nodes": Object {
|
"nodes": Object {
|
||||||
"{\\"id\\":\\"hero_of_time#0\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"hero_of_time#0\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"PC\\"}": Object {
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"mighty_bananas#1\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"FOOD\\"}": Object {
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"razorclaw_crab#2\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"FOOD\\"}": Object {
|
||||||
"payload": Object {},
|
"payload": Object {},
|
||||||
},
|
},
|
||||||
"{\\"id\\":\\"seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"demoType\\"}": Object {
|
"{\\"id\\":\\"seafood_fruit_mix#3\\",\\"pluginName\\":\\"hill_cooking_pot\\",\\"repositoryName\\":\\"sourcecred/eventide\\",\\"type\\":\\"FOOD\\"}": Object {
|
||||||
"payload": Object {
|
"payload": Object {
|
||||||
"effect": Array [
|
"effect": Array [
|
||||||
"attack_power",
|
"attack_power",
|
||||||
|
|
|
@ -133,7 +133,7 @@ describe("graph", () => {
|
||||||
expect(
|
expect(
|
||||||
demoData
|
demoData
|
||||||
.simpleMealGraph()
|
.simpleMealGraph()
|
||||||
.getNode(demoData.makeAddress("treasure_octorok#5"))
|
.getNode(demoData.makeAddress("treasure_octorok#5", "NPC"))
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -143,7 +143,8 @@ describe("graph", () => {
|
||||||
.simpleMealGraph()
|
.simpleMealGraph()
|
||||||
.getNode(
|
.getNode(
|
||||||
demoData.makeAddress(
|
demoData.makeAddress(
|
||||||
"treasure_octorok#5@helps_cook@seafood_fruit_mix#3"
|
"treasure_octorok#5@helps_cook@seafood_fruit_mix#3",
|
||||||
|
"ACTION"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
|
@ -180,10 +181,11 @@ describe("graph", () => {
|
||||||
it("allows adding an edge with dangling `dst`", () => {
|
it("allows adding an edge with dangling `dst`", () => {
|
||||||
const edge = () => ({
|
const edge = () => ({
|
||||||
address: demoData.makeAddress(
|
address: demoData.makeAddress(
|
||||||
"treasure_octorok#5@helps_cook@seafood_fruit_mix#3"
|
"treasure_octorok#5@helps_cook@seafood_fruit_mix#3",
|
||||||
|
"ACTION"
|
||||||
),
|
),
|
||||||
src: demoData.mealNode().address,
|
src: demoData.mealNode().address,
|
||||||
dst: demoData.makeAddress("treasure_octorok#5"),
|
dst: demoData.makeAddress("treasure_octorok#5", "NPC"),
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
const g = demoData.simpleMealGraph().addEdge(edge());
|
const g = demoData.simpleMealGraph().addEdge(edge());
|
||||||
|
@ -193,9 +195,10 @@ describe("graph", () => {
|
||||||
it("allows adding an edge with dangling `src`", () => {
|
it("allows adding an edge with dangling `src`", () => {
|
||||||
const edge = () => ({
|
const edge = () => ({
|
||||||
address: demoData.makeAddress(
|
address: demoData.makeAddress(
|
||||||
"health_bar#6@healed_by@seafood_fruit_mix#3"
|
"health_bar#6@healed_by@seafood_fruit_mix#3",
|
||||||
|
"PLAYER_EFFECT"
|
||||||
),
|
),
|
||||||
src: demoData.makeAddress("health_bar#6"),
|
src: demoData.makeAddress("health_bar#6", "PLAYER_STATE"),
|
||||||
dst: demoData.mealNode().address,
|
dst: demoData.mealNode().address,
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
|
@ -365,24 +368,24 @@ describe("graph", () => {
|
||||||
it("gets empty out-edges for a nonexistent node", () => {
|
it("gets empty out-edges for a nonexistent node", () => {
|
||||||
const result = demoData
|
const result = demoData
|
||||||
.simpleMealGraph()
|
.simpleMealGraph()
|
||||||
.getOutEdges(demoData.makeAddress("hinox"));
|
.getOutEdges(demoData.makeAddress("hinox", "NPC"));
|
||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("gets empty in-edges for a nonexistent node", () => {
|
it("gets empty in-edges for a nonexistent node", () => {
|
||||||
const result = demoData
|
const result = demoData
|
||||||
.simpleMealGraph()
|
.simpleMealGraph()
|
||||||
.getInEdges(demoData.makeAddress("hinox"));
|
.getInEdges(demoData.makeAddress("hinox", "NPC"));
|
||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
{
|
{
|
||||||
const danglingSrc = () => ({
|
const danglingSrc = () => ({
|
||||||
address: demoData.makeAddress("meaty_rice_balls#8"),
|
address: demoData.makeAddress("meaty_rice_balls#8", "FOOD"),
|
||||||
payload: {meaty: true},
|
payload: {meaty: true},
|
||||||
});
|
});
|
||||||
const danglingDst = () => ({
|
const danglingDst = () => ({
|
||||||
address: demoData.makeAddress("treasure_octorok#5"),
|
address: demoData.makeAddress("treasure_octorok#5", "NPC"),
|
||||||
payload: {meaty: false},
|
payload: {meaty: false},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -390,7 +393,8 @@ describe("graph", () => {
|
||||||
// demo meal graph.
|
// demo meal graph.
|
||||||
const fullyDanglingEdge = () => ({
|
const fullyDanglingEdge = () => ({
|
||||||
address: demoData.makeAddress(
|
address: demoData.makeAddress(
|
||||||
"treasure_octorok#5@helps_cook@meaty_rice_balls#8"
|
"treasure_octorok#5@helps_cook@meaty_rice_balls#8",
|
||||||
|
"ACTION"
|
||||||
),
|
),
|
||||||
src: danglingSrc().address,
|
src: danglingSrc().address,
|
||||||
dst: danglingDst().address,
|
dst: danglingDst().address,
|
||||||
|
@ -526,11 +530,11 @@ describe("graph", () => {
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
const extraNode1 = () => ({
|
const extraNode1 = () => ({
|
||||||
address: demoData.makeAddress("octorok"),
|
address: demoData.makeAddress("octorok", "NPC"),
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
const extraNode2 = () => ({
|
const extraNode2 = () => ({
|
||||||
address: demoData.makeAddress("hinox"),
|
address: demoData.makeAddress("hinox", "NPC"),
|
||||||
payload: {status: "sleeping"},
|
payload: {status: "sleeping"},
|
||||||
});
|
});
|
||||||
it("returns false when the LHS has edges missing in the RHS", () => {
|
it("returns false when the LHS has edges missing in the RHS", () => {
|
||||||
|
@ -626,20 +630,32 @@ describe("graph", () => {
|
||||||
|
|
||||||
it("conservatively merges graphs of different payload types", () => {
|
it("conservatively merges graphs of different payload types", () => {
|
||||||
const data = {
|
const data = {
|
||||||
a: () => ({address: demoData.makeAddress("a"), payload: "alpha"}),
|
a: () => ({
|
||||||
b: () => ({address: demoData.makeAddress("b"), payload: "bravo"}),
|
address: demoData.makeAddress("a", "EXPERIMENT"),
|
||||||
|
payload: "alpha",
|
||||||
|
}),
|
||||||
|
b: () => ({
|
||||||
|
address: demoData.makeAddress("b", "EXPERIMENT"),
|
||||||
|
payload: "bravo",
|
||||||
|
}),
|
||||||
u: () => ({
|
u: () => ({
|
||||||
address: demoData.makeAddress("u"),
|
address: demoData.makeAddress("u", "EXPERIMENT"),
|
||||||
src: demoData.makeAddress("a"),
|
src: demoData.makeAddress("a", "EXPERIMENT"),
|
||||||
dst: demoData.makeAddress("b"),
|
dst: demoData.makeAddress("b", "EXPERIMENT"),
|
||||||
payload: 21,
|
payload: 21,
|
||||||
}),
|
}),
|
||||||
c: () => ({address: demoData.makeAddress("c"), payload: true}),
|
c: () => ({
|
||||||
d: () => ({address: demoData.makeAddress("d"), payload: false}),
|
address: demoData.makeAddress("c", "EXPERIMENT"),
|
||||||
|
payload: true,
|
||||||
|
}),
|
||||||
|
d: () => ({
|
||||||
|
address: demoData.makeAddress("d", "EXPERIMENT"),
|
||||||
|
payload: false,
|
||||||
|
}),
|
||||||
v: () => ({
|
v: () => ({
|
||||||
address: demoData.makeAddress("v"),
|
address: demoData.makeAddress("v", "EXPERIMENT"),
|
||||||
src: demoData.makeAddress("c"),
|
src: demoData.makeAddress("c", "EXPERIMENT"),
|
||||||
dst: demoData.makeAddress("d"),
|
dst: demoData.makeAddress("d", "EXPERIMENT"),
|
||||||
payload: null,
|
payload: null,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
@ -666,7 +682,7 @@ describe("graph", () => {
|
||||||
it("conservatively rejects a graph with conflicting nodes", () => {
|
it("conservatively rejects a graph with conflicting nodes", () => {
|
||||||
const makeGraph: (nodePayload: string) => Graph<*, *> = (nodePayload) =>
|
const makeGraph: (nodePayload: string) => Graph<*, *> = (nodePayload) =>
|
||||||
new Graph().addNode({
|
new Graph().addNode({
|
||||||
address: demoData.makeAddress("conflicting-node"),
|
address: demoData.makeAddress("conflicting-node", "EXPERIMENT"),
|
||||||
payload: nodePayload,
|
payload: nodePayload,
|
||||||
});
|
});
|
||||||
const g1 = makeGraph("one");
|
const g1 = makeGraph("one");
|
||||||
|
@ -677,14 +693,14 @@ describe("graph", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("conservatively rejects a graph with conflicting edges", () => {
|
it("conservatively rejects a graph with conflicting edges", () => {
|
||||||
const srcAddress = demoData.makeAddress("src");
|
const srcAddress = demoData.makeAddress("src", "EXPERIMENT");
|
||||||
const dstAddress = demoData.makeAddress("dst");
|
const dstAddress = demoData.makeAddress("dst", "EXPERIMENT");
|
||||||
const makeGraph: (edgePayload: string) => Graph<*, *> = (edgePayload) =>
|
const makeGraph: (edgePayload: string) => Graph<*, *> = (edgePayload) =>
|
||||||
new Graph()
|
new Graph()
|
||||||
.addNode({address: srcAddress, payload: {}})
|
.addNode({address: srcAddress, payload: {}})
|
||||||
.addNode({address: dstAddress, payload: {}})
|
.addNode({address: dstAddress, payload: {}})
|
||||||
.addEdge({
|
.addEdge({
|
||||||
address: demoData.makeAddress("conflicting-edge"),
|
address: demoData.makeAddress("conflicting-edge", "EXPERIMENT"),
|
||||||
src: srcAddress,
|
src: srcAddress,
|
||||||
dst: dstAddress,
|
dst: dstAddress,
|
||||||
payload: edgePayload,
|
payload: edgePayload,
|
||||||
|
@ -775,11 +791,11 @@ describe("graph", () => {
|
||||||
it("allows adding explicitly typed nodes", () => {
|
it("allows adding explicitly typed nodes", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const stringNode: Node<string> = {
|
const stringNode: Node<string> = {
|
||||||
address: demoData.makeAddress("hello"),
|
address: demoData.makeAddress("hello", "EXPERIMENT"),
|
||||||
payload: "hello",
|
payload: "hello",
|
||||||
};
|
};
|
||||||
const numberNode: Node<number> = {
|
const numberNode: Node<number> = {
|
||||||
address: demoData.makeAddress("hello"),
|
address: demoData.makeAddress("hello", "EXPERIMENT"),
|
||||||
payload: 17,
|
payload: 17,
|
||||||
};
|
};
|
||||||
// This will be a Graph<string | number, *>.
|
// This will be a Graph<string | number, *>.
|
||||||
|
@ -789,16 +805,22 @@ describe("graph", () => {
|
||||||
|
|
||||||
it("allows adding explicitly typed edges", () => {
|
it("allows adding explicitly typed edges", () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const src = {address: demoData.makeAddress("src"), payload: {}};
|
const src = {
|
||||||
const dst = {address: demoData.makeAddress("dst"), payload: {}};
|
address: demoData.makeAddress("src", "EXPERIMENT"),
|
||||||
|
payload: {},
|
||||||
|
};
|
||||||
|
const dst = {
|
||||||
|
address: demoData.makeAddress("dst", "EXPERIMENT"),
|
||||||
|
payload: {},
|
||||||
|
};
|
||||||
const stringEdge: Edge<string> = {
|
const stringEdge: Edge<string> = {
|
||||||
address: demoData.makeAddress("hello"),
|
address: demoData.makeAddress("hello", "EXPERIMENT"),
|
||||||
src: src.address,
|
src: src.address,
|
||||||
dst: dst.address,
|
dst: dst.address,
|
||||||
payload: "hello",
|
payload: "hello",
|
||||||
};
|
};
|
||||||
const numberEdge: Edge<number> = {
|
const numberEdge: Edge<number> = {
|
||||||
address: demoData.makeAddress("hello"),
|
address: demoData.makeAddress("hello", "EXPERIMENT"),
|
||||||
src: src.address,
|
src: src.address,
|
||||||
dst: dst.address,
|
dst: dst.address,
|
||||||
payload: 18,
|
payload: 18,
|
||||||
|
@ -818,7 +840,7 @@ describe("graph", () => {
|
||||||
const g1 = demoData.advancedMealGraph();
|
const g1 = demoData.advancedMealGraph();
|
||||||
const g2 = g1.copy();
|
const g2 = g1.copy();
|
||||||
const newNode = () => ({
|
const newNode = () => ({
|
||||||
address: demoData.makeAddress("brand-new"),
|
address: demoData.makeAddress("brand-new", "EXPERIMENT"),
|
||||||
payload: 777,
|
payload: 777,
|
||||||
});
|
});
|
||||||
g2.addNode(newNode());
|
g2.addNode(newNode());
|
||||||
|
|
|
@ -7,46 +7,46 @@
|
||||||
import type {Address} from "./address";
|
import type {Address} from "./address";
|
||||||
import {Graph} from "./graph";
|
import {Graph} from "./graph";
|
||||||
|
|
||||||
export function makeAddress(id: string): Address {
|
export function makeAddress(id: string, type: string): Address {
|
||||||
return {
|
return {
|
||||||
repositoryName: "sourcecred/eventide",
|
repositoryName: "sourcecred/eventide",
|
||||||
pluginName: "hill_cooking_pot",
|
pluginName: "hill_cooking_pot",
|
||||||
type: "demoType",
|
|
||||||
id,
|
id,
|
||||||
|
type,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
export const heroNode = () => ({
|
export const heroNode = () => ({
|
||||||
address: makeAddress("hero_of_time#0"),
|
address: makeAddress("hero_of_time#0", "PC"),
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const bananasNode = () => ({
|
export const bananasNode = () => ({
|
||||||
address: makeAddress("mighty_bananas#1"),
|
address: makeAddress("mighty_bananas#1", "FOOD"),
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const crabNode = () => ({
|
export const crabNode = () => ({
|
||||||
address: makeAddress("razorclaw_crab#2"),
|
address: makeAddress("razorclaw_crab#2", "FOOD"),
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const mealNode = () => ({
|
export const mealNode = () => ({
|
||||||
address: makeAddress("seafood_fruit_mix#3"),
|
address: makeAddress("seafood_fruit_mix#3", "FOOD"),
|
||||||
payload: {
|
payload: {
|
||||||
effect: ["attack_power", 1],
|
effect: ["attack_power", 1],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
export const pickEdge = () => ({
|
export const pickEdge = () => ({
|
||||||
address: makeAddress("hero_of_time#0@picks@mighty_bananas#1"),
|
address: makeAddress("hero_of_time#0@picks@mighty_bananas#1", "ACTION"),
|
||||||
src: bananasNode().address,
|
src: bananasNode().address,
|
||||||
dst: heroNode().address,
|
dst: heroNode().address,
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const grabEdge = () => ({
|
export const grabEdge = () => ({
|
||||||
address: makeAddress("hero_of_time#0@grabs@razorclaw_crab#2"),
|
address: makeAddress("hero_of_time#0@grabs@razorclaw_crab#2", "ACTION"),
|
||||||
src: crabNode().address,
|
src: crabNode().address,
|
||||||
dst: heroNode().address,
|
dst: heroNode().address,
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const cookEdge = () => ({
|
export const cookEdge = () => ({
|
||||||
address: makeAddress("hero_of_time#0@cooks@seafood_fruit_mix#3"),
|
address: makeAddress("hero_of_time#0@cooks@seafood_fruit_mix#3", "ACTION"),
|
||||||
src: mealNode().address,
|
src: mealNode().address,
|
||||||
dst: heroNode().address,
|
dst: heroNode().address,
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -54,19 +54,25 @@ export const cookEdge = () => ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
export const bananasIngredientEdge = () => ({
|
export const bananasIngredientEdge = () => ({
|
||||||
address: makeAddress("mighty_bananas#1@included_in@seafood_fruit_mix#3"),
|
address: makeAddress(
|
||||||
|
"mighty_bananas#1@included_in@seafood_fruit_mix#3",
|
||||||
|
"INGREDIENT"
|
||||||
|
),
|
||||||
src: mealNode().address,
|
src: mealNode().address,
|
||||||
dst: bananasNode().address,
|
dst: bananasNode().address,
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const crabIngredientEdge = () => ({
|
export const crabIngredientEdge = () => ({
|
||||||
address: makeAddress("razorclaw_crab#2@included_in@seafood_fruit_mix#3"),
|
address: makeAddress(
|
||||||
|
"razorclaw_crab#2@included_in@seafood_fruit_mix#3",
|
||||||
|
"INGREDIENT"
|
||||||
|
),
|
||||||
src: mealNode().address,
|
src: mealNode().address,
|
||||||
dst: crabNode().address,
|
dst: crabNode().address,
|
||||||
payload: {},
|
payload: {},
|
||||||
});
|
});
|
||||||
export const eatEdge = () => ({
|
export const eatEdge = () => ({
|
||||||
address: makeAddress("hero_of_time#0@eats@seafood_fruit_mix#3"),
|
address: makeAddress("hero_of_time#0@eats@seafood_fruit_mix#3", "ACTION"),
|
||||||
src: heroNode().address,
|
src: heroNode().address,
|
||||||
dst: mealNode().address,
|
dst: mealNode().address,
|
||||||
payload: {},
|
payload: {},
|
||||||
|
@ -85,14 +91,17 @@ export const simpleMealGraph = () =>
|
||||||
.addEdge(eatEdge());
|
.addEdge(eatEdge());
|
||||||
|
|
||||||
export const crabLoopEdge = () => ({
|
export const crabLoopEdge = () => ({
|
||||||
address: makeAddress("crab-self-assessment"),
|
address: makeAddress("crab-self-assessment", "SILLY"),
|
||||||
src: crabNode().address,
|
src: crabNode().address,
|
||||||
dst: crabNode().address,
|
dst: crabNode().address,
|
||||||
payload: {evaluation: "not effective at avoiding hero"},
|
payload: {evaluation: "not effective at avoiding hero"},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const duplicateCookEdge = () => ({
|
export const duplicateCookEdge = () => ({
|
||||||
address: makeAddress("hero_of_time#0@again_cooks@seafood_fruit_mix#3"),
|
address: makeAddress(
|
||||||
|
"hero_of_time#0@again_cooks@seafood_fruit_mix#3",
|
||||||
|
"ACTION"
|
||||||
|
),
|
||||||
src: mealNode().address,
|
src: mealNode().address,
|
||||||
dst: heroNode().address,
|
dst: heroNode().address,
|
||||||
payload: {
|
payload: {
|
||||||
|
|
Loading…
Reference in New Issue