stigmergy 1.0.93 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/stigmergy +26 -12
- package/bin/stigmergy.cmd +1 -1
- package/docs/HASH_TABLE.md +83 -0
- package/docs/WEATHER_PROCESSOR_API.md +230 -0
- package/docs/best_practices.md +135 -0
- package/docs/development_guidelines.md +392 -0
- package/docs/requirements_specification.md +148 -0
- package/docs/system_design.md +314 -0
- package/docs/tdd_implementation_plan.md +384 -0
- package/docs/test_report.md +49 -0
- package/examples/calculator-example.js +72 -0
- package/examples/json-validation-example.js +64 -0
- package/examples/rest-client-example.js +52 -0
- package/package.json +21 -17
- package/scripts/post-deployment-config.js +9 -2
- package/src/auth.js +171 -0
- package/src/auth_command.js +195 -0
- package/src/calculator.js +220 -0
- package/src/core/cli_help_analyzer.js +625 -562
- package/src/core/cli_parameter_handler.js +121 -0
- package/src/core/cli_tools.js +89 -0
- package/src/core/error_handler.js +307 -0
- package/src/core/memory_manager.js +76 -0
- package/src/core/smart_router.js +133 -0
- package/src/deploy.js +50 -0
- package/src/main_english.js +643 -720
- package/src/main_fixed.js +1035 -0
- package/src/utils.js +529 -0
- package/src/weatherProcessor.js +205 -0
- package/test/calculator.test.js +215 -0
- package/test/collision-test.js +26 -0
- package/test/csv-processing-test.js +36 -0
- package/test/e2e/claude-cli-test.js +128 -0
- package/test/e2e/collaboration-test.js +75 -0
- package/test/e2e/comprehensive-test.js +431 -0
- package/test/e2e/error-handling-test.js +90 -0
- package/test/e2e/individual-tool-test.js +143 -0
- package/test/e2e/other-cli-test.js +130 -0
- package/test/e2e/qoder-cli-test.js +128 -0
- package/test/e2e/run-e2e-tests.js +73 -0
- package/test/e2e/test-data.js +88 -0
- package/test/e2e/test-utils.js +222 -0
- package/test/hash-table-demo.js +33 -0
- package/test/hash-table-test.js +26 -0
- package/test/json-validation-test.js +164 -0
- package/test/rest-client-test.js +56 -0
- package/test/unit/calculator-full.test.js +191 -0
- package/test/unit/calculator-simple.test.js +96 -0
- package/test/unit/calculator.test.js +97 -0
- package/test/unit/cli_parameter_handler.test.js +116 -0
- package/test/weather-processor.test.js +104 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weather Data Processing Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides functions for processing weather data from various sources
|
|
5
|
+
* and converting it into standardized formats for analysis and display.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Process raw weather data and generate standardized output
|
|
10
|
+
* @param {Object} rawData - Raw weather data from API or sensor
|
|
11
|
+
* @param {Object} options - Processing options
|
|
12
|
+
* @param {string} options.unit - Temperature unit ('celsius', 'fahrenheit', 'kelvin')
|
|
13
|
+
* @param {boolean} options.includeForecasts - Whether to include forecast data
|
|
14
|
+
* @param {number} options.forecastDays - Number of forecast days to include (1-7)
|
|
15
|
+
* @returns {Object} Processed weather data with standardized format
|
|
16
|
+
* @throws {Error} If input data is invalid or missing required fields
|
|
17
|
+
*/
|
|
18
|
+
function processWeatherData(rawData, options = {}) {
|
|
19
|
+
// Validate input
|
|
20
|
+
if (!rawData || typeof rawData !== 'object') {
|
|
21
|
+
throw new Error('Invalid weather data: must be an object');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Default options
|
|
25
|
+
const opts = {
|
|
26
|
+
unit: 'celsius',
|
|
27
|
+
includeForecasts: false,
|
|
28
|
+
forecastDays: 5,
|
|
29
|
+
...options
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Validate options
|
|
33
|
+
if (!['celsius', 'fahrenheit', 'kelvin'].includes(opts.unit)) {
|
|
34
|
+
throw new Error('Invalid unit: must be "celsius", "fahrenheit", or "kelvin"');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (opts.forecastDays < 1 || opts.forecastDays > 7) {
|
|
38
|
+
throw new Error('Invalid forecastDays: must be between 1 and 7');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Process current weather data
|
|
42
|
+
const processedData = {
|
|
43
|
+
timestamp: new Date().toISOString(),
|
|
44
|
+
location: _extractLocation(rawData),
|
|
45
|
+
current: _processCurrentWeather(rawData.current || rawData, opts.unit),
|
|
46
|
+
forecasts: opts.includeForecasts ? _processForecastData(rawData.forecast || [], opts) : []
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return processedData;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Extract location information from raw data
|
|
54
|
+
* @param {Object} data - Raw weather data
|
|
55
|
+
* @returns {Object} Location information
|
|
56
|
+
*/
|
|
57
|
+
function _extractLocation(data) {
|
|
58
|
+
// Handle various location formats from different APIs
|
|
59
|
+
if (data.location) {
|
|
60
|
+
return {
|
|
61
|
+
name: data.location.name || data.location.city || 'Unknown',
|
|
62
|
+
country: data.location.country || '',
|
|
63
|
+
coordinates: {
|
|
64
|
+
lat: data.location.lat || data.location.latitude || 0,
|
|
65
|
+
lon: data.location.lon || data.location.longitude || 0
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (data.city) {
|
|
71
|
+
return {
|
|
72
|
+
name: data.city.name || data.city,
|
|
73
|
+
country: data.city.country || '',
|
|
74
|
+
coordinates: {
|
|
75
|
+
lat: data.city.coord?.lat || data.city.latitude || 0,
|
|
76
|
+
lon: data.city.coord?.lon || data.city.longitude || 0
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
name: 'Unknown',
|
|
83
|
+
country: '',
|
|
84
|
+
coordinates: { lat: 0, lon: 0 }
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Process current weather data
|
|
90
|
+
* @param {Object} current - Current weather data
|
|
91
|
+
* @param {string} unit - Temperature unit
|
|
92
|
+
* @returns {Object} Processed current weather data
|
|
93
|
+
*/
|
|
94
|
+
function _processCurrentWeather(current, unit) {
|
|
95
|
+
if (!current) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Convert temperature to requested unit
|
|
100
|
+
const temp = _convertTemperature(current.temp || current.temperature || 0, 'kelvin', unit);
|
|
101
|
+
const feelsLike = _convertTemperature(current.feels_like || current.feelsLike || temp, 'kelvin', unit);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
temperature: {
|
|
105
|
+
value: temp,
|
|
106
|
+
unit: unit,
|
|
107
|
+
feelsLike: feelsLike
|
|
108
|
+
},
|
|
109
|
+
humidity: current.humidity || current.humididy || 0,
|
|
110
|
+
pressure: current.pressure || 0,
|
|
111
|
+
wind: {
|
|
112
|
+
speed: current.wind_speed || current.windSpeed || 0,
|
|
113
|
+
direction: current.wind_deg || current.windDirection || 0
|
|
114
|
+
},
|
|
115
|
+
visibility: current.visibility || 0,
|
|
116
|
+
cloudiness: current.clouds || current.cloudiness || 0,
|
|
117
|
+
description: current.description || current.weather?.[0]?.description || 'Unknown',
|
|
118
|
+
icon: current.icon || current.weather?.[0]?.icon || ''
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Process forecast data
|
|
124
|
+
* @param {Array} forecasts - Array of forecast data
|
|
125
|
+
* @param {Object} options - Processing options
|
|
126
|
+
* @returns {Array} Processed forecast data
|
|
127
|
+
*/
|
|
128
|
+
function _processForecastData(forecasts, options) {
|
|
129
|
+
if (!Array.isArray(forecasts)) {
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Limit forecasts to requested number of days
|
|
134
|
+
const limitedForecasts = forecasts.slice(0, options.forecastDays);
|
|
135
|
+
|
|
136
|
+
return limitedForecasts.map(forecast => {
|
|
137
|
+
const date = forecast.dt ? new Date(forecast.dt * 1000).toISOString().split('T')[0] :
|
|
138
|
+
forecast.date || new Date().toISOString().split('T')[0];
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
date: date,
|
|
142
|
+
temperature: {
|
|
143
|
+
min: _convertTemperature(forecast.temp?.min || forecast.min_temp || 0, 'kelvin', options.unit),
|
|
144
|
+
max: _convertTemperature(forecast.temp?.max || forecast.max_temp || 0, 'kelvin', options.unit),
|
|
145
|
+
unit: options.unit
|
|
146
|
+
},
|
|
147
|
+
humidity: forecast.humidity || 0,
|
|
148
|
+
pressure: forecast.pressure || 0,
|
|
149
|
+
wind: {
|
|
150
|
+
speed: forecast.wind_speed || forecast.windSpeed || 0,
|
|
151
|
+
direction: forecast.wind_deg || forecast.windDirection || 0
|
|
152
|
+
},
|
|
153
|
+
precipitation: {
|
|
154
|
+
probability: forecast.pop || forecast.precipitation_probability || 0,
|
|
155
|
+
amount: forecast.rain || forecast.snow || 0
|
|
156
|
+
},
|
|
157
|
+
description: forecast.weather?.[0]?.description || forecast.description || 'Unknown'
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Convert temperature between units
|
|
164
|
+
* @param {number} value - Temperature value
|
|
165
|
+
* @param {string} fromUnit - Source unit ('celsius', 'fahrenheit', 'kelvin')
|
|
166
|
+
* @param {string} toUnit - Target unit ('celsius', 'fahrenheit', 'kelvin')
|
|
167
|
+
* @returns {number} Converted temperature value
|
|
168
|
+
*/
|
|
169
|
+
function _convertTemperature(value, fromUnit, toUnit) {
|
|
170
|
+
if (fromUnit === toUnit) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Convert to Celsius first
|
|
175
|
+
let celsius;
|
|
176
|
+
switch (fromUnit) {
|
|
177
|
+
case 'celsius':
|
|
178
|
+
celsius = value;
|
|
179
|
+
break;
|
|
180
|
+
case 'fahrenheit':
|
|
181
|
+
celsius = (value - 32) * 5/9;
|
|
182
|
+
break;
|
|
183
|
+
case 'kelvin':
|
|
184
|
+
celsius = value - 273.15;
|
|
185
|
+
break;
|
|
186
|
+
default:
|
|
187
|
+
celsius = value;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Convert from Celsius to target unit
|
|
191
|
+
switch (toUnit) {
|
|
192
|
+
case 'celsius':
|
|
193
|
+
return celsius;
|
|
194
|
+
case 'fahrenheit':
|
|
195
|
+
return (celsius * 9/5) + 32;
|
|
196
|
+
case 'kelvin':
|
|
197
|
+
return celsius + 273.15;
|
|
198
|
+
default:
|
|
199
|
+
return celsius;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
module.exports = {
|
|
204
|
+
processWeatherData
|
|
205
|
+
};
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for Calculator class
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const Calculator = require('../src/calculator');
|
|
6
|
+
|
|
7
|
+
console.log("Testing Calculator class...");
|
|
8
|
+
|
|
9
|
+
// Test basic operations
|
|
10
|
+
console.log("\n1. Testing basic arithmetic operations:");
|
|
11
|
+
|
|
12
|
+
const calc = new Calculator();
|
|
13
|
+
|
|
14
|
+
// Test addition
|
|
15
|
+
console.log("\n1.1 Testing addition:");
|
|
16
|
+
try {
|
|
17
|
+
const sum = calc.add(5, 3);
|
|
18
|
+
console.log(`calc.add(5, 3) = ${sum}`);
|
|
19
|
+
if (sum === 8) {
|
|
20
|
+
console.log("✅ Addition test passed");
|
|
21
|
+
} else {
|
|
22
|
+
console.log("❌ Addition test failed");
|
|
23
|
+
}
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.log("❌ Addition test failed with error:", error.message);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Test subtraction
|
|
29
|
+
console.log("\n1.2 Testing subtraction:");
|
|
30
|
+
try {
|
|
31
|
+
const difference = calc.subtract(10, 4);
|
|
32
|
+
console.log(`calc.subtract(10, 4) = ${difference}`);
|
|
33
|
+
if (difference === 6) {
|
|
34
|
+
console.log("✅ Subtraction test passed");
|
|
35
|
+
} else {
|
|
36
|
+
console.log("❌ Subtraction test failed");
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.log("❌ Subtraction test failed with error:", error.message);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Test multiplication
|
|
43
|
+
console.log("\n1.3 Testing multiplication:");
|
|
44
|
+
try {
|
|
45
|
+
const product = calc.multiply(6, 7);
|
|
46
|
+
console.log(`calc.multiply(6, 7) = ${product}`);
|
|
47
|
+
if (product === 42) {
|
|
48
|
+
console.log("✅ Multiplication test passed");
|
|
49
|
+
} else {
|
|
50
|
+
console.log("❌ Multiplication test failed");
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.log("❌ Multiplication test failed with error:", error.message);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Test division
|
|
57
|
+
console.log("\n1.4 Testing division:");
|
|
58
|
+
try {
|
|
59
|
+
const quotient = calc.divide(15, 3);
|
|
60
|
+
console.log(`calc.divide(15, 3) = ${quotient}`);
|
|
61
|
+
if (quotient === 5) {
|
|
62
|
+
console.log("✅ Division test passed");
|
|
63
|
+
} else {
|
|
64
|
+
console.log("❌ Division test failed");
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.log("❌ Division test failed with error:", error.message);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Test division by zero
|
|
71
|
+
console.log("\n1.5 Testing division by zero:");
|
|
72
|
+
try {
|
|
73
|
+
calc.divide(10, 0);
|
|
74
|
+
console.log("❌ Division by zero test failed - should have thrown an error");
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.log("✅ Division by zero correctly threw error:", error.message);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Test power function
|
|
80
|
+
console.log("\n1.6 Testing power function:");
|
|
81
|
+
try {
|
|
82
|
+
const powerResult = calc.power(2, 3);
|
|
83
|
+
console.log(`calc.power(2, 3) = ${powerResult}`);
|
|
84
|
+
if (powerResult === 8) {
|
|
85
|
+
console.log("✅ Power test passed");
|
|
86
|
+
} else {
|
|
87
|
+
console.log("❌ Power test failed");
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.log("❌ Power test failed with error:", error.message);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Test square root
|
|
94
|
+
console.log("\n1.7 Testing square root:");
|
|
95
|
+
try {
|
|
96
|
+
const sqrtResult = calc.sqrt(16);
|
|
97
|
+
console.log(`calc.sqrt(16) = ${sqrtResult}`);
|
|
98
|
+
if (sqrtResult === 4) {
|
|
99
|
+
console.log("✅ Square root test passed");
|
|
100
|
+
} else {
|
|
101
|
+
console.log("❌ Square root test failed");
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.log("❌ Square root test failed with error:", error.message);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Test square root of negative number
|
|
108
|
+
console.log("\n1.8 Testing square root of negative number:");
|
|
109
|
+
try {
|
|
110
|
+
calc.sqrt(-4);
|
|
111
|
+
console.log("❌ Square root of negative number test failed - should have thrown an error");
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.log("✅ Square root of negative number correctly threw error:", error.message);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Test factorial
|
|
117
|
+
console.log("\n1.9 Testing factorial:");
|
|
118
|
+
try {
|
|
119
|
+
const factorialResult = calc.factorial(5);
|
|
120
|
+
console.log(`calc.factorial(5) = ${factorialResult}`);
|
|
121
|
+
if (factorialResult === 120) {
|
|
122
|
+
console.log("✅ Factorial test passed");
|
|
123
|
+
} else {
|
|
124
|
+
console.log("❌ Factorial test failed");
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.log("❌ Factorial test failed with error:", error.message);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Test factorial of 0
|
|
131
|
+
console.log("\n1.10 Testing factorial of 0:");
|
|
132
|
+
try {
|
|
133
|
+
const factorialZero = calc.factorial(0);
|
|
134
|
+
console.log(`calc.factorial(0) = ${factorialZero}`);
|
|
135
|
+
if (factorialZero === 1) {
|
|
136
|
+
console.log("✅ Factorial of 0 test passed");
|
|
137
|
+
} else {
|
|
138
|
+
console.log("❌ Factorial of 0 test failed");
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.log("❌ Factorial of 0 test failed with error:", error.message);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Test factorial of negative number
|
|
145
|
+
console.log("\n1.11 Testing factorial of negative number:");
|
|
146
|
+
try {
|
|
147
|
+
calc.factorial(-5);
|
|
148
|
+
console.log("❌ Factorial of negative number test failed - should have thrown an error");
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.log("✅ Factorial of negative number correctly threw error:", error.message);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Test percentage
|
|
154
|
+
console.log("\n1.12 Testing percentage:");
|
|
155
|
+
try {
|
|
156
|
+
const percentageResult = calc.percentage(25, 100);
|
|
157
|
+
console.log(`calc.percentage(25, 100) = ${percentageResult}%`);
|
|
158
|
+
if (percentageResult === 25) {
|
|
159
|
+
console.log("✅ Percentage test passed");
|
|
160
|
+
} else {
|
|
161
|
+
console.log("❌ Percentage test failed");
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.log("❌ Percentage test failed with error:", error.message);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Test percentage with zero as whole
|
|
168
|
+
console.log("\n1.13 Testing percentage with zero as whole:");
|
|
169
|
+
try {
|
|
170
|
+
calc.percentage(50, 0);
|
|
171
|
+
console.log("❌ Percentage with zero as whole test failed - should have thrown an error");
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.log("✅ Percentage with zero as whole correctly threw error:", error.message);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Test calculation chain
|
|
177
|
+
console.log("\n2. Testing calculation chain:");
|
|
178
|
+
|
|
179
|
+
console.log("\n2.1 Testing chain operations:");
|
|
180
|
+
try {
|
|
181
|
+
const chainResult = calc.chain(10).add(5).multiply(2).subtract(4).divide(2).equals();
|
|
182
|
+
console.log(`calc.chain(10).add(5).multiply(2).subtract(4).divide(2).equals() = ${chainResult}`);
|
|
183
|
+
// ((10 + 5) * 2 - 4) / 2 = (30 - 4) / 2 = 26 / 2 = 13
|
|
184
|
+
if (chainResult === 13) {
|
|
185
|
+
console.log("✅ Chain operations test passed");
|
|
186
|
+
} else {
|
|
187
|
+
console.log("❌ Chain operations test failed");
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.log("❌ Chain operations test failed with error:", error.message);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
console.log("\n2.2 Testing chain division by zero:");
|
|
194
|
+
try {
|
|
195
|
+
calc.chain(10).divide(0);
|
|
196
|
+
console.log("❌ Chain division by zero test failed - should have thrown an error");
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.log("✅ Chain division by zero correctly threw error:", error.message);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
console.log("\n2.3 Testing chain value method:");
|
|
202
|
+
try {
|
|
203
|
+
const chain = calc.chain(5).add(3);
|
|
204
|
+
const currentValue = chain.value();
|
|
205
|
+
console.log(`calc.chain(5).add(3).value() = ${currentValue}`);
|
|
206
|
+
if (currentValue === 8) {
|
|
207
|
+
console.log("✅ Chain value method test passed");
|
|
208
|
+
} else {
|
|
209
|
+
console.log("❌ Chain value method test failed");
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.log("❌ Chain value method test failed with error:", error.message);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
console.log("\n✅ All Calculator tests completed!");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { HashTable } = require('../src/utils');
|
|
2
|
+
|
|
3
|
+
console.log("=== Hash Table Collision Handling Demo ===");
|
|
4
|
+
|
|
5
|
+
// Create a hash table with a small size to force collisions
|
|
6
|
+
const ht = new HashTable(4); // Small size to demonstrate collisions
|
|
7
|
+
|
|
8
|
+
// Add several key-value pairs that will cause collisions
|
|
9
|
+
ht.set("key1", "value1");
|
|
10
|
+
ht.set("key2", "value2");
|
|
11
|
+
ht.set("key3", "value3");
|
|
12
|
+
ht.set("key4", "value4");
|
|
13
|
+
ht.set("key5", "value5"); // This will collide with one of the above
|
|
14
|
+
|
|
15
|
+
console.log("Values retrieved:");
|
|
16
|
+
console.log("key1:", ht.get("key1"));
|
|
17
|
+
console.log("key2:", ht.get("key2"));
|
|
18
|
+
console.log("key3:", ht.get("key3"));
|
|
19
|
+
console.log("key4:", ht.get("key4"));
|
|
20
|
+
console.log("key5:", ht.get("key5"));
|
|
21
|
+
console.log("nonexistent_key:", ht.get("nonexistent_key"));
|
|
22
|
+
|
|
23
|
+
console.log("\nAll keys:", ht.keys());
|
|
24
|
+
console.log("All values:", ht.values());
|
|
25
|
+
|
|
26
|
+
console.log("\n=== Test completed successfully! ===");
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { processCSV } = require('../src/utils');
|
|
2
|
+
|
|
3
|
+
// Test basic CSV processing
|
|
4
|
+
console.log('Testing basic CSV processing...');
|
|
5
|
+
|
|
6
|
+
const csvData = `name,age,city
|
|
7
|
+
John,25,New York
|
|
8
|
+
Jane,30,Boston
|
|
9
|
+
Bob,35,Chicago
|
|
10
|
+
Alice,28,Los Angeles`;
|
|
11
|
+
|
|
12
|
+
const stats = processCSV(csvData);
|
|
13
|
+
console.log('Basic CSV Stats:', JSON.stringify(stats, null, 2));
|
|
14
|
+
|
|
15
|
+
// Test CSV without headers
|
|
16
|
+
console.log('\nTesting CSV without headers...');
|
|
17
|
+
|
|
18
|
+
const csvWithoutHeaders = `John,25,New York
|
|
19
|
+
Jane,30,Boston
|
|
20
|
+
Bob,35,Chicago`;
|
|
21
|
+
|
|
22
|
+
const statsNoHeaders = processCSV(csvWithoutHeaders, { hasHeader: false });
|
|
23
|
+
console.log('CSV without headers Stats:', JSON.stringify(statsNoHeaders, null, 2));
|
|
24
|
+
|
|
25
|
+
// Test CSV with numeric data
|
|
26
|
+
console.log('\nTesting CSV with numeric data...');
|
|
27
|
+
|
|
28
|
+
const csvNumeric = `product,price,quantity
|
|
29
|
+
Apple,1.20,100
|
|
30
|
+
Banana,0.50,200
|
|
31
|
+
Orange,0.80,150`;
|
|
32
|
+
|
|
33
|
+
const statsNumeric = processCSV(csvNumeric);
|
|
34
|
+
console.log('Numeric CSV Stats:', JSON.stringify(statsNumeric, null, 2));
|
|
35
|
+
|
|
36
|
+
console.log('\nCSV processing tests completed successfully!');
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Claude CLI Integration Tests
|
|
2
|
+
const { executeCommand, recordTestResult } = require('./test-utils');
|
|
3
|
+
|
|
4
|
+
async function testClaudeCLIIntegration() {
|
|
5
|
+
console.log('Starting Claude CLI integration testing...\n');
|
|
6
|
+
|
|
7
|
+
// Test 1: Simple code generation
|
|
8
|
+
console.log('--- Test 1: Simple code generation ---');
|
|
9
|
+
try {
|
|
10
|
+
const result = await executeCommand('node src/main_english.js call "claude write a simple Python function to add two numbers"', 45000);
|
|
11
|
+
|
|
12
|
+
const passed = result.success &&
|
|
13
|
+
result.stdout.length > 100 &&
|
|
14
|
+
result.stdout.includes('def') &&
|
|
15
|
+
result.stdout.includes('return') &&
|
|
16
|
+
!result.stdout.includes('Error') &&
|
|
17
|
+
!result.stdout.includes('error');
|
|
18
|
+
|
|
19
|
+
recordTestResult('Claude CLI - Simple Code Generation', passed, {
|
|
20
|
+
command: result.command,
|
|
21
|
+
executionTime: result.executionTime,
|
|
22
|
+
outputLength: result.stdout.length,
|
|
23
|
+
hasError: !result.success || result.stderr.length > 0
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
console.log(` Result: ${passed ? 'PASS' : 'FAIL'}`);
|
|
27
|
+
console.log(` Execution time: ${result.executionTime}ms`);
|
|
28
|
+
console.log(` Output length: ${result.stdout.length} characters`);
|
|
29
|
+
|
|
30
|
+
} catch (error) {
|
|
31
|
+
recordTestResult('Claude CLI - Simple Code Generation', false, {
|
|
32
|
+
error: error.message
|
|
33
|
+
});
|
|
34
|
+
console.log(` Result: FAIL - ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Test 2: Complex algorithm implementation
|
|
38
|
+
console.log('\n--- Test 2: Complex algorithm implementation ---');
|
|
39
|
+
try {
|
|
40
|
+
const result = await executeCommand('node src/main_english.js call "claude implement a binary search algorithm in Python with proper error handling"', 60000);
|
|
41
|
+
|
|
42
|
+
const passed = result.success &&
|
|
43
|
+
result.stdout.length > 200 &&
|
|
44
|
+
(result.stdout.includes('def') || result.stdout.includes('class')) &&
|
|
45
|
+
result.stdout.includes('binary') &&
|
|
46
|
+
!result.stdout.includes('Error') &&
|
|
47
|
+
!result.stdout.includes('error');
|
|
48
|
+
|
|
49
|
+
recordTestResult('Claude CLI - Complex Algorithm Implementation', passed, {
|
|
50
|
+
command: result.command,
|
|
51
|
+
executionTime: result.executionTime,
|
|
52
|
+
outputLength: result.stdout.length,
|
|
53
|
+
hasError: !result.success || result.stderr.length > 0
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log(` Result: ${passed ? 'PASS' : 'FAIL'}`);
|
|
57
|
+
console.log(` Execution time: ${result.executionTime}ms`);
|
|
58
|
+
console.log(` Output length: ${result.stdout.length} characters`);
|
|
59
|
+
|
|
60
|
+
} catch (error) {
|
|
61
|
+
recordTestResult('Claude CLI - Complex Algorithm Implementation', false, {
|
|
62
|
+
error: error.message
|
|
63
|
+
});
|
|
64
|
+
console.log(` Result: FAIL - ${error.message}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Test 3: Code analysis and review
|
|
68
|
+
console.log('\n--- Test 3: Code analysis and review ---');
|
|
69
|
+
try {
|
|
70
|
+
const result = await executeCommand('node src/main_english.js call "claude analyze this Python code for potential security vulnerabilities: def login(user, password): if user == \"admin\" and password == \"123456\": return True"', 45000);
|
|
71
|
+
|
|
72
|
+
const passed = result.success &&
|
|
73
|
+
result.stdout.length > 100 &&
|
|
74
|
+
(result.stdout.includes('security') || result.stdout.includes('vulnerab')) &&
|
|
75
|
+
!result.stdout.includes('Error') &&
|
|
76
|
+
!result.stdout.includes('error');
|
|
77
|
+
|
|
78
|
+
recordTestResult('Claude CLI - Code Analysis and Review', passed, {
|
|
79
|
+
command: result.command,
|
|
80
|
+
executionTime: result.executionTime,
|
|
81
|
+
outputLength: result.stdout.length,
|
|
82
|
+
hasError: !result.success || result.stderr.length > 0
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
console.log(` Result: ${passed ? 'PASS' : 'FAIL'}`);
|
|
86
|
+
console.log(` Execution time: ${result.executionTime}ms`);
|
|
87
|
+
console.log(` Output length: ${result.stdout.length} characters`);
|
|
88
|
+
|
|
89
|
+
} catch (error) {
|
|
90
|
+
recordTestResult('Claude CLI - Code Analysis and Review', false, {
|
|
91
|
+
error: error.message
|
|
92
|
+
});
|
|
93
|
+
console.log(` Result: FAIL - ${error.message}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Test 4: Documentation generation
|
|
97
|
+
console.log('\n--- Test 4: Documentation generation ---');
|
|
98
|
+
try {
|
|
99
|
+
const result = await executeCommand('node src/main_english.js call "claude generate documentation for a Python function that sorts arrays"', 45000);
|
|
100
|
+
|
|
101
|
+
const passed = result.success &&
|
|
102
|
+
result.stdout.length > 100 &&
|
|
103
|
+
(result.stdout.includes('def') || result.stdout.includes('function') || result.stdout.includes('doc')) &&
|
|
104
|
+
!result.stdout.includes('Error') &&
|
|
105
|
+
!result.stdout.includes('error');
|
|
106
|
+
|
|
107
|
+
recordTestResult('Claude CLI - Documentation Generation', passed, {
|
|
108
|
+
command: result.command,
|
|
109
|
+
executionTime: result.executionTime,
|
|
110
|
+
outputLength: result.stdout.length,
|
|
111
|
+
hasError: !result.success || result.stderr.length > 0
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
console.log(` Result: ${passed ? 'PASS' : 'FAIL'}`);
|
|
115
|
+
console.log(` Execution time: ${result.executionTime}ms`);
|
|
116
|
+
console.log(` Output length: ${result.stdout.length} characters`);
|
|
117
|
+
|
|
118
|
+
} catch (error) {
|
|
119
|
+
recordTestResult('Claude CLI - Documentation Generation', false, {
|
|
120
|
+
error: error.message
|
|
121
|
+
});
|
|
122
|
+
console.log(` Result: FAIL - ${error.message}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log('\n--- Claude CLI integration testing completed ---\n');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = testClaudeCLIIntegration;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Collaboration functionality testing
|
|
2
|
+
const { executeCommand, recordTestResult, wait } = require('./test-utils');
|
|
3
|
+
const testData = require('./test-data');
|
|
4
|
+
|
|
5
|
+
async function testCollaboration() {
|
|
6
|
+
console.log('Starting collaboration functionality testing...\n');
|
|
7
|
+
|
|
8
|
+
// Test each collaboration scenario
|
|
9
|
+
for (const scenario of testData.collaborationScenarios) {
|
|
10
|
+
console.log(`\n--- Testing ${scenario.name} ---`);
|
|
11
|
+
|
|
12
|
+
let allStepsPassed = true;
|
|
13
|
+
const stepResults = [];
|
|
14
|
+
|
|
15
|
+
// Execute each step in the scenario
|
|
16
|
+
for (let i = 0; i < scenario.steps.length; i++) {
|
|
17
|
+
const step = scenario.steps[i];
|
|
18
|
+
console.log(` Step ${i + 1}: ${step}`);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const result = await executeCommand(`stigmergy call "${step}"`, 60000);
|
|
22
|
+
|
|
23
|
+
// Check if the command executed successfully
|
|
24
|
+
const stepPassed = result.success &&
|
|
25
|
+
result.stdout.length > 30 &&
|
|
26
|
+
!result.stdout.includes('Error') &&
|
|
27
|
+
!result.stdout.includes('error');
|
|
28
|
+
|
|
29
|
+
stepResults.push({
|
|
30
|
+
step: i + 1,
|
|
31
|
+
command: step,
|
|
32
|
+
passed: stepPassed,
|
|
33
|
+
executionTime: result.executionTime,
|
|
34
|
+
outputLength: result.stdout.length
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!stepPassed) {
|
|
38
|
+
allStepsPassed = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Log result summary
|
|
42
|
+
console.log(` Result: ${stepPassed ? 'PASS' : 'FAIL'}`);
|
|
43
|
+
console.log(` Execution time: ${result.executionTime}ms`);
|
|
44
|
+
console.log(` Output length: ${result.stdout.length} characters`);
|
|
45
|
+
|
|
46
|
+
// Wait a bit between steps to avoid overwhelming the system
|
|
47
|
+
await wait(2000);
|
|
48
|
+
|
|
49
|
+
} catch (error) {
|
|
50
|
+
stepResults.push({
|
|
51
|
+
step: i + 1,
|
|
52
|
+
command: step,
|
|
53
|
+
passed: false,
|
|
54
|
+
error: error.message
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
allStepsPassed = false;
|
|
58
|
+
console.log(` Result: FAIL - ${error.message}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Record overall scenario result
|
|
63
|
+
recordTestResult(`Collaboration - ${scenario.name}`, allStepsPassed, {
|
|
64
|
+
steps: stepResults,
|
|
65
|
+
totalSteps: scenario.steps.length,
|
|
66
|
+
passedSteps: stepResults.filter(s => s.passed).length
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
console.log(` Overall: ${allStepsPassed ? 'PASS' : 'FAIL'}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
console.log('\n--- Collaboration testing completed ---\n');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = testCollaboration;
|