-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.js
More file actions
107 lines (107 loc) · 4.38 KB
/
testing.js
File metadata and controls
107 lines (107 loc) · 4.38 KB
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
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const firstNames = [
'James', 'Mary', 'John', 'Patricia', 'Robert', 'Jennifer', 'Michael', 'Linda',
'William', 'Elizabeth', 'David', 'Barbara', 'Richard', 'Susan', 'Joseph', 'Jessica',
'Thomas', 'Sarah', 'Charles', 'Karen', 'Christopher', 'Nancy', 'Daniel', 'Lisa',
'Matthew', 'Betty', 'Anthony', 'Margaret', 'Donald', 'Sandra', 'Mark', 'Ashley',
'Paul', 'Dorothy', 'Steven', 'Emily', 'Andrew', 'Emma', 'Kenneth', 'Olivia'
];
const lastNames = [
'Smith', 'Johnson', 'Williams', 'Brown', 'Jones', 'Garcia', 'Miller', 'Davis',
'Rodriguez', 'Martinez', 'Hernandez', 'Lopez', 'Gonzalez', 'Wilson', 'Anderson',
'Thomas', 'Taylor', 'Moore', 'Jackson', 'Martin', 'Lee', 'Perez', 'Thompson',
'White', 'Harris', 'Sanchez', 'Clark', 'Ramirez', 'Lewis', 'Robinson', 'Walker',
'Young', 'Allen', 'King', 'Wright', 'Scott', 'Torres', 'Nguyen', 'Hill', 'Flores'
];
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generateRandomStudent(id) {
const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
const grades = Array.from({ length: 5 }, () => getRandomInt(0, 100));
return {
uniqueID: `STU${id.toString().padStart(3, '0')}`,
name: `${firstName} ${lastName}`,
grades: grades
};
}
function formatGrade(grade) {
return grade.toFixed(2);
}
function getTimestamp() {
const now = new Date();
return now.toISOString()
.replace(/:/g, '-')
.replace(/\..+/, '')
.replace('T', '_');
}
//makes the file
function writeStudentDataToFile(students, analyzer) {
const filename = path.join(__dirname, 'data.txt');
const content = students.map(student => {
const average = analyzer.averageGrade(student.grades);
return `${student.name}, ${student.uniqueID}, ${formatGrade(average)}%, [${student.grades.join(', ')}]`;
}).join('\n');
fs.writeFileSync(filename, content, 'utf8');
console.log(`\nStudent list has been saved to: ${filename}`);
}
function runAnalyzerTest() {
const analyzer = new index_1.StudentGradeAnalyzer();
const allStudents = [];
for (let i = 1; i <= 50; i++) {
const student = generateRandomStudent(i);
analyzer.addStudent(student);
allStudents.push(student);
}
console.log(`Average grade of all students: ${formatGrade(analyzer.calculateOverallAverage())}%`);
const topStudent = analyzer.findTopStudent();
if (topStudent) {
console.log(`Top student: ${topStudent.name}`);
}
const passingStudents = analyzer.getPassingStudents();
console.log('Students who passed:');
passingStudents.forEach(student => {
console.log(student.name);
});
writeStudentDataToFile(allStudents, analyzer);
console.log('\n' + '='.repeat(50));
}
runAnalyzerTest();