Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
benchristel committed Sep 24, 2024
1 parent 97b487a commit 1b238b8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("mafsStateToInteractiveGraph", () => {
const graph: PerseusGraphType = {
type: "angle",
match: "congruent",
}
};
const state: AngleGraphState = {
...commonGraphState,
type: "angle",
Expand All @@ -45,7 +45,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "angle",
Expand All @@ -64,8 +67,8 @@ describe("mafsStateToInteractiveGraph", () => {
startCoords: {
radius: 3,
center: [4, 5],
}
}
},
};
const state: CircleGraphState = {
type: "circle",
center: [1, 2],
Expand All @@ -78,7 +81,10 @@ describe("mafsStateToInteractiveGraph", () => {
snapStep: [9, 9],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "circle",
Expand All @@ -87,15 +93,15 @@ describe("mafsStateToInteractiveGraph", () => {
startCoords: {
radius: 3,
center: [4, 5],
}
},
});
});

it("converts the state of a segment graph", () => {
const graph: PerseusGraphType = {
type: "segment",
numSegments: 7,
}
};
const state: SegmentGraphState = {
...commonGraphState,
type: "segment",
Expand All @@ -107,7 +113,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "segment",
Expand All @@ -127,8 +136,8 @@ describe("mafsStateToInteractiveGraph", () => {
startCoords: [
[5, 6],
[7, 8],
]
}
],
};
const state: LinearGraphState = {
...commonGraphState,
type: "linear",
Expand All @@ -138,7 +147,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "linear",
Expand All @@ -149,7 +161,7 @@ describe("mafsStateToInteractiveGraph", () => {
startCoords: [
[5, 6],
[7, 8],
]
],
});
});

Expand All @@ -160,9 +172,9 @@ describe("mafsStateToInteractiveGraph", () => {
[
[9, 10],
[11, 12],
]
]
}
],
],
};
const state: LinearSystemGraphState = {
...commonGraphState,
type: "linear-system",
Expand All @@ -178,7 +190,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "linear-system",
Expand All @@ -196,8 +211,8 @@ describe("mafsStateToInteractiveGraph", () => {
[
[9, 10],
[11, 12],
]
]
],
],
});
});

Expand All @@ -207,8 +222,8 @@ describe("mafsStateToInteractiveGraph", () => {
startCoords: [
[5, 6],
[7, 8],
]
}
],
};
const state: RayGraphState = {
...commonGraphState,
type: "ray",
Expand All @@ -218,7 +233,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "ray",
Expand All @@ -228,16 +246,16 @@ describe("mafsStateToInteractiveGraph", () => {
],
startCoords: [
[5, 6],
[7, 8]
]
[7, 8],
],
});
});

it("converts the state of a polygon graph", () => {
const graph: PerseusGraphType = {
type: "polygon",
match: "approx",
}
};
const state: PolygonGraphState = {
...commonGraphState,
type: "polygon",
Expand All @@ -251,7 +269,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "polygon",
Expand All @@ -268,10 +289,8 @@ describe("mafsStateToInteractiveGraph", () => {
const graph: PerseusGraphType = {
type: "point",
numPoints: "unlimited",
startCoords: [
[7, 8],
],
}
startCoords: [[7, 8]],
};
const state: PointGraphState = {
...commonGraphState,
type: "point",
Expand All @@ -287,7 +306,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "point",
Expand All @@ -297,9 +319,7 @@ describe("mafsStateToInteractiveGraph", () => {
[3, 4],
[5, 6],
],
startCoords: [
[7, 8],
]
startCoords: [[7, 8]],
});
});

Expand All @@ -310,8 +330,8 @@ describe("mafsStateToInteractiveGraph", () => {
[7, 8],
[9, 10],
[11, 12],
]
}
],
};
const state: QuadraticGraphState = {
...commonGraphState,
type: "quadratic",
Expand All @@ -322,7 +342,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "quadratic",
Expand All @@ -335,7 +358,7 @@ describe("mafsStateToInteractiveGraph", () => {
[7, 8],
[9, 10],
[11, 12],
]
],
});
});

Expand All @@ -346,7 +369,7 @@ describe("mafsStateToInteractiveGraph", () => {
[5, 6],
[7, 8],
],
}
};
const state: SinusoidGraphState = {
...commonGraphState,
type: "sinusoid",
Expand All @@ -356,7 +379,10 @@ describe("mafsStateToInteractiveGraph", () => {
],
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "sinusoid",
Expand All @@ -374,13 +400,16 @@ describe("mafsStateToInteractiveGraph", () => {
it("converts the state of a none-type graph", () => {
const graph: PerseusGraphType = {
type: "none",
}
};
const state: NoneGraphState = {
...commonGraphState,
type: "none",
};

const result: PerseusGraphType = mafsStateToInteractiveGraph(state, graph);
const result: PerseusGraphType = mafsStateToInteractiveGraph(
state,
graph,
);

expect(result).toEqual({
type: "none",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {UnreachableCaseError} from "@khanacademy/wonder-stuff-core";
import invariant from "tiny-invariant";

import {getRadius} from "./reducer/interactive-graph-state";

import type {InteractiveGraphState} from "./types";
import type {PerseusGraphType} from "@khanacademy/perseus";
import invariant from "tiny-invariant";

// Converts the state of a StatefulMafsGraph back to the format used to
// represent graph state in the widget JSON.
Expand All @@ -28,68 +28,68 @@ export function mafsStateToInteractiveGraph(
): PerseusGraphType {
switch (state.type) {
case "angle":
invariant(originalGraph.type === "angle")
invariant(originalGraph.type === "angle");
return {
...originalGraph,
coords: state.coords,
};
case "quadratic":
invariant(originalGraph.type === "quadratic")
invariant(originalGraph.type === "quadratic");
return {
...originalGraph,
coords: state.coords,
};
case "circle":
invariant(originalGraph.type === "circle")
invariant(originalGraph.type === "circle");
return {
...originalGraph,
center: state.center,
radius: getRadius(state),
};
case "linear":
invariant(originalGraph.type === "linear")
invariant(originalGraph.type === "linear");
return {
...originalGraph,
coords: state.coords,
}
};
case "ray":
invariant(originalGraph.type === "ray")
invariant(originalGraph.type === "ray");
return {
...originalGraph,
coords: state.coords,
}
};
case "sinusoid":
invariant(originalGraph.type === "sinusoid")
invariant(originalGraph.type === "sinusoid");
return {
...originalGraph,
coords: state.coords,
};
case "segment":
invariant(originalGraph.type === "segment")
invariant(originalGraph.type === "segment");
return {
...originalGraph,
coords: state.coords,
};
case "linear-system":
invariant(originalGraph.type === "linear-system")
invariant(originalGraph.type === "linear-system");
return {
...originalGraph,
coords: state.coords,
};
case "polygon":
invariant(originalGraph.type === "polygon")
invariant(originalGraph.type === "polygon");
return {
...originalGraph,
coords: state.coords,
}
};
case "point":
invariant(originalGraph.type === "point")
invariant(originalGraph.type === "point");
return {
...originalGraph,
coords: state.coords,
};
case "none":
invariant(originalGraph.type === "none")
invariant(originalGraph.type === "none");
return {...originalGraph};
default:
throw new UnreachableCaseError(state);
Expand Down
Loading

0 comments on commit 1b238b8

Please sign in to comment.