Skip to content

Commit 99d68c2

Browse files
authored
Refactor solver name retrieval to use getSolverName() method for consistency (#17)
1 parent 804a273 commit 99d68c2

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/BaseSolver.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export class BaseSolver {
2424
stats: Record<string, any> = {}
2525
_setupDone = false
2626

27+
getSolverName(): string {
28+
return this.constructor.name
29+
}
30+
2731
setup() {
2832
if (this._setupDone) return
2933
this._setup()
@@ -44,15 +48,15 @@ export class BaseSolver {
4448
try {
4549
this._step()
4650
} catch (e) {
47-
this.error = `${this.constructor.name} error: ${e}`
51+
this.error = `${this.getSolverName()} error: ${e}`
4852
this.failed = true
4953
throw e
5054
}
5155
if (!this.solved && this.iterations >= this.MAX_ITERATIONS) {
5256
this.tryFinalAcceptance()
5357
}
5458
if (!this.solved && this.iterations >= this.MAX_ITERATIONS) {
55-
this.error = `${this.constructor.name} ran out of iterations`
59+
this.error = `${this.getSolverName()} ran out of iterations`
5660
this.failed = true
5761
}
5862
if ("computeProgress" in this) {

lib/react/DownloadDropdown.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const DownloadDropdown = ({
4949
try {
5050
if (typeof solver.getConstructorParams !== "function") {
5151
alert(
52-
`getConstructorParams() is not implemented for ${solver.constructor.name}`,
52+
`getConstructorParams() is not implemented for ${solver.getSolverName()}`,
5353
)
5454
return
5555
}
@@ -63,12 +63,12 @@ export const DownloadDropdown = ({
6363
const url = URL.createObjectURL(blob)
6464
const a = document.createElement("a")
6565
a.href = url
66-
a.download = `${solver.constructor.name}_params.json`
66+
a.download = `${solver.getSolverName()}_params.json`
6767
a.click()
6868
URL.revokeObjectURL(url)
6969
} catch (error) {
7070
alert(
71-
`Error downloading params for ${solver.constructor.name}: ${error instanceof Error ? error.message : String(error)}`,
71+
`Error downloading params for ${solver.getSolverName()}: ${error instanceof Error ? error.message : String(error)}`,
7272
)
7373
}
7474
setIsOpen(false)
@@ -79,7 +79,7 @@ export const DownloadDropdown = ({
7979
const params = deepRemoveUnderscoreProperties(
8080
solver.getConstructorParams(),
8181
)
82-
const solverName = solver.constructor.name
82+
const solverName = solver.getSolverName()
8383
const isSchematicTracePipelineSolver =
8484
solverName === "SchematicTracePipelineSolver"
8585

@@ -118,7 +118,7 @@ export default () => {
118118
URL.revokeObjectURL(url)
119119
} catch (error) {
120120
alert(
121-
`Error generating page.tsx for ${solver.constructor.name}: ${error instanceof Error ? error.message : String(error)}`,
121+
`Error generating page.tsx for ${solver.getSolverName()}: ${error instanceof Error ? error.message : String(error)}`,
122122
)
123123
}
124124
setIsOpen(false)
@@ -129,7 +129,7 @@ export default () => {
129129
const params = deepRemoveUnderscoreProperties(
130130
solver.getConstructorParams(),
131131
)
132-
const solverName = solver.constructor.name
132+
const solverName = solver.getSolverName()
133133

134134
const content = `import { ${solverName} } from "lib/solvers/${solverName}/${solverName}"
135135
import { test, expect } from "bun:test"
@@ -156,7 +156,7 @@ test("${solverName} should solve problem correctly", () => {
156156
URL.revokeObjectURL(url)
157157
} catch (error) {
158158
alert(
159-
`Error generating test.ts for ${solver.constructor.name}: ${error instanceof Error ? error.message : String(error)}`,
159+
`Error generating test.ts for ${solver.getSolverName()}: ${error instanceof Error ? error.message : String(error)}`,
160160
)
161161
}
162162
setIsOpen(false)
@@ -167,9 +167,9 @@ test("${solverName} should solve problem correctly", () => {
167167
<button
168168
className="px-2 py-1 rounded text-xs cursor-pointer"
169169
onClick={() => setIsOpen(!isOpen)}
170-
title={`Download options for ${solver.constructor.name}`}
170+
title={`Download options for ${solver.getSolverName()}`}
171171
>
172-
{solver.constructor.name}
172+
{solver.getSolverName()}
173173
</button>
174174

175175
{isOpen && (

lib/react/SolverBreadcrumbInputDownloader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const SolverBreadcrumbInputDownloader = ({
2121
return (
2222
<div className="flex gap-1 items-center text-sm pt-1">
2323
{solverChain.map((s, index) => (
24-
<div key={s.constructor.name} className="flex items-center">
24+
<div key={s.getSolverName()} className="flex items-center">
2525
{index > 0 && <span className="text-gray-400 mx-1"></span>}
2626
<DownloadDropdown solver={s} />
2727
</div>

0 commit comments

Comments
 (0)