-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
infinite.html
254 lines (246 loc) · 12.5 KB
/
infinite.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Linked List Viewer with Directionality</title>
<!-- Code Completeness Rules in Meta Tags -->
<meta name="code-rule" content="Complete Implementation: Code must be fully functional and executable as provided, without additional inputs or modifications">
<meta name="code-rule" content="No Placeholder Statements: Avoid 'fill in here' or similar phrases. Code must be self-contained and immediately usable">
<meta name="code-rule" content="No Back-References to Previous Responses: Each code response must be standalone and understandable without prior context">
<meta name="code-rule" content="Clear and Detailed Instructions: Include thorough explanations or instructions alongside the code">
<meta name="code-rule" content="Contextual Completeness: Code must directly address and fulfill the specific user request or problem statement">
<meta name="code-rule" content="Self-Contained: Code must not rely on external resources or configurations not explicitly included or described in the response">
<meta name="code-rule" content="Downstream Compliance: Any modification or downstream use of the code must preserve and include these code completeness meta tags">
<meta name="code-rule" content="Full Refresh Display: Ensure that all relevant code and context are included in each response to maintain coherence and accessibility">
<!-- Duplicate of Code Completeness Rules in Comment Block -->
<!--
Code Completeness Rules:
- Complete Implementation: Code must be fully functional and executable as provided, without additional inputs or modifications.
- No Placeholder Statements: Avoid 'fill in here' or similar phrases. Code must be self-contained and immediately usable.
- No Back-References to Previous Responses: Each code response must be standalone and understandable without prior context.
- Clear and Detailed Instructions: Include thorough explanations or instructions alongside the code.
- Contextual Completeness: Code must directly address and fulfill the specific user request or problem statement.
- Self-Contained: Code must not rely on external resources or configurations not explicitly included or described in the response.
- Downstream Compliance: Any modification or downstream use of the code must preserve and include these code completeness meta tags.
- Full Refresh Display: Ensure that all relevant code and context are included in each response to maintain coherence and accessibility.
-->
<style>
html, body {
background-color: blueviolet;
color: white;
}
#controls button, #backRefs button, #dependencies button {
margin: 5px;
}
</style>
<!-- Gherkin Features and Scenarios -->
<gherkin-feature name="Linked List Viewer">
<gherkin-scenario feature="Linked List Viewer" name="Viewing Entire List" g="user has a linked list" w="user opens the Linked List Viewer" t="entire linked list is displayed in a global view"></gherkin-scenario>
<gherkin-scenario feature="Linked List Viewer" name="Navigating to Node" g="user is viewing the linked list" w="user selects a specific node" t="viewer focuses on that node"></gherkin-scenario>
<!-- Additional scenarios here -->
</gherkin-feature>
<!-- Additional features here -->
</head>
<body>
<h1>Linked List Viewer</h1>
<div id="currentNode"></div>
<div id="backRefs"><strong>← Links to this node:</strong></div>
<div id="dependencies"><strong>Dependencies (relies on):</strong></div>
<div id="controls"><strong>Links from this node →</strong></div>
<div>
<button onclick="viewer.goToHome()">Home</button>
<button onclick="viewer.goBack()">Back</button>
<button onclick="viewer.goForward()">Forward</button>
<button onclick="saveToLocalStorage()">Save to Local Storage</button>
<button onclick="loadFromLocalStorage()">Load from Local Storage</button>
</div>
<script>
class Node {
constructor(value, image) {
this.value = value;
this.image = image; // New image property
this.references = [];
this.dependencies = new Set();
this.backReferences = new Set();
this.id = Math.random().toString(36).substr(2, 9);
}
addReference(node, isDependency = false) {
node.backReferences.add(this);
this.references.push(node);
if (isDependency) {
this.dependencies.add(node);
node.backReferences.add(this); // Indicate a bi-directional dependency
}
}
}
class LinkedListViewer {
constructor(root, allNodes) {
this.root = root;
this.currentNode = root;
this.history = [];
this.historyIndex = -1;
this.allNodes = allNodes;
this.updateView();
}
goTo(node) {
this.currentNode = node;
this.history = this.history.slice(0, this.historyIndex + 1);
this.history.push(node);
this.historyIndex++;
this.updateView();
}
goToHome() { this.goTo(this.root); }
goBack() {
if (this.historyIndex > 0) {
this.historyIndex--;
this.currentNode = this.history[this.historyIndex];
this.updateView();
}
}
goForward() {
if (this.historyIndex < this.history.length - 1) {
this.historyIndex++;
this.currentNode = this.history[this.historyIndex];
this.updateView();
}
}
updateView() {
const currentNodeDiv = document.getElementById('currentNode');
currentNodeDiv.innerHTML = `<h2>${this.currentNode.value}</h2>`;
const img = document.createElement('img');
img.src = this.currentNode.image;
img.style.width = '100px';
img.style.height = '100px';
currentNodeDiv.appendChild(img);
this.updateBackRefsView();
this.updateDependenciesView();
this.updateControlsView();
}
updateBackRefsView() {
const backRefsDiv = document.getElementById('backRefs');
backRefsDiv.innerHTML = '<strong>← Links to this node:</strong><br>';
this.currentNode.backReferences.forEach(ref => {
const btn = document.createElement('button');
btn.textContent = ref.value + (this.currentNode.dependencies.has(ref) ? " (mutual)" : "");
btn.onclick = () => this.goTo(ref);
backRefsDiv.appendChild(btn);
});
}
updateDependenciesView() {
const dependenciesDiv = document.getElementById('dependencies');
dependenciesDiv.innerHTML = '<strong>Dependencies (relies on):</strong><br>';
this.currentNode.dependencies.forEach(dep => {
const btn = document.createElement('button');
btn.textContent = dep.value;
btn.onclick = () => this.goTo(dep);
dependenciesDiv.appendChild(btn);
});
}
updateControlsView() {
const controlsDiv = document.getElementById('controls');
controlsDiv.innerHTML = '<strong>Links from this node →</strong><br>';
this.currentNode.references.forEach(ref => {
const btn = document.createElement('button');
btn.textContent = ref.value;
btn.onclick = () => this.goTo(ref);
controlsDiv.appendChild(btn);
});
}
serialize() {
const serialized = { nodes: {}, rootId: this.root.id };
this.allNodes.forEach((node, id) => {
serialized.nodes[id] = { value: node.value, references: node.references.map(ref => ref.id) };
});
return JSON.stringify(serialized);
}
deserialize(serialized) {
const data = JSON.parse(serialized);
const nodes = new Map();
for (let id in data.nodes) {
nodes.set(id, new Node(data.nodes[id].value));
}
nodes.forEach((node, id) => {
data.nodes[id].references.forEach(refId => node.addReference(nodes.get(refId)));
});
this.root = nodes.get(data.rootId);
this.currentNode = this.root;
this.history = [];
this.historyIndex = -1;
this.allNodes = nodes;
this.updateView();
}
}
let viewer;
let allNodes = new Map();
function setupSampleData() {
const root = new Node('root', 'root.jpg');
const home = new Node('home', 'home.jpg');
const myRoom = new Node('my room');
const mySketchbook = new Node('my sketchbook');
const myIdeas = new Node('my ideas');
const boomerangIdeas = new Node('boomerang ideas');
const conversationMapperApp = new Node('conversation mapper app');
const space = new Node('space');
const spacetime = new Node('spacetime');
const time = new Node('time');
const myVideos = new Node('my videos');
const myPictures = new Node('my pictures');
const myMusic = new Node('my music');
const myBookmarks = new Node('my bookmarks');
const myWorkbench = new Node('my workbench');
[home, space, spacetime, time, myVideos, myPictures, myMusic, myBookmarks, myWorkbench, mySketchbook, myIdeas, boomerangIdeas, conversationMapperApp].forEach(node => allNodes.set(node.id, node));
root.addReference(home);
home.addReference(myRoom);
myRoom.addReference(mySketchbook);
mySketchbook.addReference(myIdeas);
myIdeas.addReference(boomerangIdeas);
boomerangIdeas.addReference(conversationMapperApp);
space.addReference(root);
spacetime.addReference(root);
spacetime.addReference(space);
spacetime.addReference(time);
myRoom.addReference(myVideos);
myRoom.addReference(myPictures);
myRoom.addReference(myMusic);
myRoom.addReference(myBookmarks);
myRoom.addReference(myWorkbench);
viewer = new LinkedListViewer(root, allNodes);
}
function saveToLocalStorage() {
localStorage.setItem('linkedListViewerData', viewer.serialize());
}
function loadFromLocalStorage() {
const serializedData = localStorage.getItem('linkedListViewerData');
if (serializedData) {
viewer.deserialize(serializedData);
} else {
alert('No saved data found.');
}
}
document.addEventListener('DOMContentLoaded', setupSampleData);
</script>
<script>
// JavaScript for Parsing Gherkin Features and Scenarios
document.querySelectorAll('gherkin-feature').forEach(feature => {
const featureName = feature.getAttribute('name');
feature.querySelectorAll('gherkin-scenario').forEach(scenario => {
const scenarioName = scenario.getAttribute('name');
const given = scenario.getAttribute('g');
const when = scenario.getAttribute('w');
const then = scenario.getAttribute('t');
// Conceptual Mapping to Test Functions
const testFnName = `test_${featureName}_${scenarioName}`.replace(/\s+/g, '_');
window[testFnName] = () => {
console.log(`Running test for ${scenarioName}: ${given}, ${when}, ${then}`);
// Test implementation logic here
};
});
});
// Example of executing a specific test
const testToRun = 'test_Linked_List_Viewer_Viewing_Entire_List';
if (window[testToRun]) {
window[testToRun]();
}
</script>
</body>
</html>