Skip to content

Commit

Permalink
test: combo string generator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Nov 14, 2023
1 parent 3331ef8 commit da7783a
Show file tree
Hide file tree
Showing 2 changed files with 302 additions and 0 deletions.
197 changes: 197 additions & 0 deletions tests/Feature/ComboStringGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?php

namespace Tests\Feature;

use App\DataParser\Generators\ComboStringGenerator;
use App\Models\LteComponent;
use App\Models\Mimo;
use App\Models\NrComponent;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ComboStringGeneratorTest extends TestCase
{
use RefreshDatabase;
use ArraySubsetAsserts;

protected $seed = true;

protected static $auth = [
'x-auth-token' => 'admin',
];

/**
* Creates combo string for LTE only combo with mimo.
*/
public function test_generates_combo_for_lte_only_with_mimo()
{
$g = new ComboStringGenerator();

$m4d = Mimo::firstOrCreate(['mimo' => 4, 'is_ul' => false]);
$m2d = Mimo::firstOrCreate(['mimo' => 2, 'is_ul' => false]);
$m2u = Mimo::firstOrCreate(['mimo' => 2, 'is_ul' => true]);
$m1u = Mimo::firstOrCreate(['mimo' => 1, 'is_ul' => true]);

// 1C4A
$c1 = new LteComponent([
'band' => 1,
'dl_class' => 'C',
'ul_class' => 'A',
'component_index' => 1,
]);
$c1->save();
$c1->mimos()->sync([
$m4d->id,
$m1u->id,
]);

// 3A4
$c2 = new LteComponent([
'band' => 3,
'dl_class' => 'A',
'component_index' => 2,
]);
$c2->save();
$c2->mimos()->sync([
$m4d->id,
$m2d->id,
]);

$components = [
$c1,
$c2,
];

$comboString = $g->getComboStringFromComponents($components);

$this->assertEquals('3A4-1C4A', $comboString);
}

/**
* Creates combo string for NR only combo with mimo.
*/
public function test_generates_combo_for_nr_only_with_mimo()
{
$g = new ComboStringGenerator();

$m4d = Mimo::firstOrCreate(['mimo' => 4, 'is_ul' => false]);
$m2d = Mimo::firstOrCreate(['mimo' => 2, 'is_ul' => false]);
$m2u = Mimo::firstOrCreate(['mimo' => 2, 'is_ul' => true]);
$m1u = Mimo::firstOrCreate(['mimo' => 1, 'is_ul' => true]);

// 1C4A
$c1 = new NrComponent([
'band' => 1,
'dl_class' => 'C',
'ul_class' => 'A',
'component_index' => 1,
]);
$c1->save();
$c1->mimos()->sync([
$m4d->id,
$m1u->id,
$m2u->id,
]);

// 3A4
$c2 = new NrComponent([
'band' => 3,
'dl_class' => 'A',
'component_index' => 2,
]);
$c2->save();
$c2->mimos()->sync([
$m2d->id,
$m4d->id,
]);

$components = [
$c1,
$c2,
];

$comboString = $g->getComboStringFromComponents($components);

$this->assertEquals('n3A4-n1C4A2', $comboString);
}

/**
* Creates combo string for ENDC combo with mimo.
*/
public function test_generates_combo_for_endc_with_mimo()
{
$g = new ComboStringGenerator();

/** @var Mimo */
$m4d = Mimo::firstOrCreate(['mimo' => 4, 'is_ul' => 0]);
/** @var Mimo */
$m2d = Mimo::firstOrCreate(['mimo' => 2, 'is_ul' => 0]);
/** @var Mimo */
$m2u = Mimo::firstOrCreate(['mimo' => 2, 'is_ul' => 1]);
/** @var Mimo */
$m1u = Mimo::firstOrCreate(['mimo' => 1, 'is_ul' => 1]);

// 28A4A
$c1 = new LteComponent([
'band' => 28,
'dl_class' => 'A',
'ul_class' => 'A',
'component_index' => 1,
]);
$c1->save();
$c1->mimos()->sync([
$m4d->id,
$m1u->id,
]);

// 7C
$c2 = new LteComponent([
'band' => 7,
'dl_class' => 'C',
'component_index' => 2,
]);
$c2->save();
$c2->mimos()->sync([
$m4d->id,
$m2d->id,
]);

// n1C4A2
$c3 = new NrComponent([
'band' => 1,
'dl_class' => 'C',
'ul_class' => 'A',
'component_index' => 3,
]);
$c3->save();
$c3->mimos()->sync([
$m4d->id,
$m1u->id,
$m2u->id,
]);

// n3A4
$c4 = new NrComponent([
'band' => 3,
'dl_class' => 'A',
'component_index' => 4,
]);
$c4->save();
$c4->mimos()->sync([
$m2d->id,
$m4d->id,
]);

$components = [
$c1,
$c2,
$c3,
$c4
];

$comboString = $g->getComboStringFromComponents($components);

$this->assertEquals('28A4A-7C4_n3A4-n1C4A2', $comboString);
}
}
105 changes: 105 additions & 0 deletions tests/Unit/ComboStringGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace Tests\Unit;

use App\DataParser\Generators\ComboStringGenerator;
use App\Models\LteComponent;
use App\Models\NrComponent;
use Tests\UnitTestCase;

class ComboStringGeneratorTest extends UnitTestCase
{
/**
* Creates combo string for LTE only combo.
*/
public function test_generates_combo_for_lte_only_with_no_mimo()
{
$g = new ComboStringGenerator();

$components = [
new LteComponent([
'band' => 1,
'dl_class' => 'C',
'ul_class' => 'A',
]),
new LteComponent([
'band' => 2,
'dl_class' => 'C',
]),
new LteComponent([
'band' => 3,
'dl_class' => 'A',
]),
];

$comboString = $g->getComboStringFromComponents($components);

$this->assertEquals('3A-2C-1CA', $comboString);
}

/**
* Creates combo string for NR only combo.
*/
public function test_generates_combo_for_nr_only_with_no_mimo()
{
$g = new ComboStringGenerator();

$components = [
new NrComponent([
'band' => 1,
'dl_class' => 'C',
'ul_class' => 'A',
]),
new NrComponent([
'band' => 2,
'dl_class' => 'C',
]),
new NrComponent([
'band' => 3,
'dl_class' => 'A',
]),
];

$comboString = $g->getComboStringFromComponents($components);

$this->assertEquals('n3A-n2C-n1CA', $comboString);
}

/**
* Creates combo string for ENDC combo.
*/
public function test_generates_combo_for_endc_with_no_mimo()
{
$g = new ComboStringGenerator();

$components = [
new NrComponent([
'band' => 1,
'dl_class' => 'C',
'ul_class' => 'A',
]),
new NrComponent([
'band' => 2,
'dl_class' => 'C',
]),
new LteComponent([
'band' => 7,
'dl_class' => 'A',
'ul_class' => 'A',
]),
new NrComponent([
'band' => 3,
'dl_class' => 'A',
]),
new LteComponent([
'band' => 28,
'dl_class' => 'A',
'ul_class' => 'A',
]),
];

$comboString = $g->getComboStringFromComponents($components);

$this->assertEquals('28AA-7AA_n3A-n2C-n1CA', $comboString);
}
}

0 comments on commit da7783a

Please sign in to comment.