<?php
// Test script to verify individual marks with average display

// Simulate combined Bangla subject data with fractional marks
$combined_bangla = [
    'subject_name' => 'Combined Bangla',
    'cq_marks' => 24.5,
    'mcq_marks' => 12.75,
    'cq_marks_array' => [25.5, 24.0],  // Average = 24.75
    'mcq_marks_array' => [12.75, 12.25], // Average = 12.5
    'full_marks' => 100,
    'pass_marks' => 33
];

// Simulate combined English subject data with fractional marks
$combined_english = [
    'subject_name' => 'Combined English',
    'cq_marks' => 33.33,
    'mcq_marks' => 0,
    'cq_marks_array' => [35.5, 31.5],  // Average = 33.5
    'mcq_marks_array' => [0, 0],       // Average = 0
    'full_marks' => 100,
    'pass_marks' => 33
];

// Simulate regular subject data with fractional marks
$regular_subject = [
    'subject_name' => 'গণিত',
    'cq_marks' => 45.75,
    'mcq_marks' => 35.25,
    'full_marks' => 100,
    'pass_marks' => 33
];

echo "<h2>Testing Individual Marks with Average Display (Without Fractions):</h2>\n";

echo "<h3>Combined Bangla:</h3>\n";
echo "CQ Marks Display: ";
if (isset($combined_bangla['cq_marks_array'])) {
    // Show individual marks
    $individual_marks = [];
    foreach ($combined_bangla['cq_marks_array'] as $mark) {
        $individual_marks[] = floor($mark);
    }
    // Calculate average and remove fractional part
    $avg_cq = array_sum($combined_bangla['cq_marks_array']) / count($combined_bangla['cq_marks_array']);
    echo implode(', ', $individual_marks) . ' (গড়: ' . floor($avg_cq) . ')';
} else {
    echo htmlspecialchars(floor($combined_bangla['cq_marks']) ?: '-');
}
echo "<br>\n";

echo "MCQ Marks Display: ";
if (isset($combined_bangla['mcq_marks_array'])) {
    // Show individual marks
    $individual_marks = [];
    foreach ($combined_bangla['mcq_marks_array'] as $mark) {
        $individual_marks[] = floor($mark);
    }
    // Calculate average and remove fractional part
    $avg_mcq = array_sum($combined_bangla['mcq_marks_array']) / count($combined_bangla['mcq_marks_array']);
    echo implode(', ', $individual_marks) . ' (গড়: ' . floor($avg_mcq) . ')';
} else {
    echo htmlspecialchars(floor($combined_bangla['mcq_marks']) ?: '-');
}
echo "<br>\n";
echo "Expected: CQ = 25, 24 (গড়: 24), MCQ = 12, 12 (গড়: 12)<br>\n";

echo "<h3>Combined English:</h3>\n";
echo "CQ Marks Display: ";
if (isset($combined_english['cq_marks_array'])) {
    // Show individual marks
    $individual_marks = [];
    foreach ($combined_english['cq_marks_array'] as $mark) {
        $individual_marks[] = floor($mark);
    }
    // Calculate average and remove fractional part
    $avg_cq = array_sum($combined_english['cq_marks_array']) / count($combined_english['cq_marks_array']);
    echo implode(', ', $individual_marks) . ' (গড়: ' . floor($avg_cq) . ')';
} else {
    echo htmlspecialchars(floor($combined_english['cq_marks']) ?: '-');
}
echo "<br>\n";

echo "MCQ Marks Display: ";
if (isset($combined_english['mcq_marks_array'])) {
    // Show individual marks
    $individual_marks = [];
    foreach ($combined_english['mcq_marks_array'] as $mark) {
        $individual_marks[] = floor($mark);
    }
    // Calculate average and remove fractional part
    $avg_mcq = array_sum($combined_english['mcq_marks_array']) / count($combined_english['mcq_marks_array']);
    echo implode(', ', $individual_marks) . ' (গড়: ' . floor($avg_mcq) . ')';
} else {
    echo htmlspecialchars(floor($combined_english['mcq_marks']) ?: '-');
}
echo "<br>\n";
echo "Expected: CQ = 35, 31 (গড়: 33), MCQ = 0, 0 (গড়: 0)<br>\n";

echo "<h3>Regular Subject:</h3>\n";
echo "CQ Marks Display: ";
echo htmlspecialchars(floor($regular_subject['cq_marks']) ?: '-');
echo "<br>\n";

echo "MCQ Marks Display: ";
echo htmlspecialchars(floor($regular_subject['mcq_marks']) ?: '-');
echo "<br>\n";
echo "Expected: CQ = 45, MCQ = 35<br>\n";

echo "<h3>Verification:</h3>\n";
echo "Combined subjects should show individual marks with average without fractions<br>\n";
echo "Regular subjects should show single marks without fractions<br>\n";
?>