1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0028103: Foundation Classes - extend NCollection_Map to check whether two given maps are intersected

Mehtod HasIntersection added in NCollection_Map to check whether two given maps contain at least one same item.
'Draw' command and test to check the method were created.
This commit is contained in:
abk 2016-11-14 18:08:44 +03:00 committed by apn
parent f411f94fac
commit d673da182b
6 changed files with 91 additions and 39 deletions

View File

@ -383,6 +383,28 @@ class NCollection_Map : public NCollection_BaseMap
return anOldExtent != Extent();
}
//! Returns true if this and theMap have common elements.
Standard_Boolean HasIntersection (const NCollection_Map& theMap) const
{
const NCollection_Map* aMap1 = this;
const NCollection_Map* aMap2 = &theMap;
if (theMap.Size() < Size())
{
aMap1 = &theMap;
aMap2 = this;
}
for (NCollection_Map::Iterator aIt(*aMap1); aIt.More(); aIt.Next())
{
if (aMap2->Contains(aIt.Value()))
{
return Standard_True;
}
}
return Standard_False;
}
//! Sets this Map to be the result of intersection (aka multiplication, common, boolean AND) operation between two given Maps.
//! The new Map contains only the values that are contained in both map operands.
//! All previous content of this Map is cleared.

View File

@ -299,47 +299,71 @@ static void TestSequence (QANCollection_SequenceFunc& theS)
// ===================== Test methods of Map type =============================
////////////////////////////////void TestMap (QANCollection_Map& theM)
static void TestMap (QANCollection_MapFunc& theM)
static void TestMap(QANCollection_MapFunc& theM, Draw_Interpretor& theDI)
{
// Extent
Standard_Integer iExt=theM.Extent();
Standard_Integer i;
{
// Extent
Standard_Integer iExt=theM.Extent();
Standard_Integer i;
printf ("Info: testing Map(l=%d)\n", iExt);
theM.Statistics(cout);
// Resize
theM.ReSize(8);
theM.Statistics(cout);
cout.flush();
// Constructor
////////////////////////////////QANCollection_Map aM;
QANCollection_MapFunc aM;
// Add
Key1Type aKey;
for (i=0; i<8; i++)
{
Random (aKey);
aM.Add (aKey);
}
// Contains, Remove
if (!aM.Contains(aKey))
{
printf("Error : map says that it does not contain its key ");
PrintItem(aKey);
}
else
{
aM.Remove(aKey);
printf(" successfully removed item, l=%d\n", aM.Size());
}
// Copy constructor (including operator=)
////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM);
QANCollection_MapFunc aM2 = QANCollection_MapFunc(aM);
// Assign
AssignCollection (aM2,theM);
printf ("Info: testing Map(l=%d)\n", iExt);
theM.Statistics(cout);
// Resize
theM.ReSize(8);
theM.Statistics(cout);
cout.flush();
// Constructor
////////////////////////////////QANCollection_Map aM;
QANCollection_MapFunc aM;
// Add
Key1Type aKey;
for (i=0; i<8; i++)
{
Random (aKey);
aM.Add (aKey);
}
// Contains, Remove
if (!aM.Contains(aKey))
{
theDI << "Error: map says that it does not contain its key " << aKey;
}
else
{
aM.Remove(aKey);
cout << " successfully removed item, l=%d\n" << aM.Size() << "\n";
}
// Copy constructor (including operator=)
////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM);
QANCollection_MapFunc aM2 = QANCollection_MapFunc(aM);
// Assign
AssignCollection (aM2,theM);
// Clear
aM.Clear();
// Clear
aM.Clear();
}
// Check method 'HasIntersection'.
{
QANCollection_MapFunc aM1, aM2, aM3;
aM1.Add(6);
aM1.Add(8);
aM1.Add(10);
aM2.Add(4);
aM2.Add(8);
aM2.Add(16);
aM3.Add(1);
aM3.Add(2);
aM3.Add(3);
if (!aM1.HasIntersection(aM2) || !aM2.HasIntersection(aM1) ||
aM1.HasIntersection(aM3) || aM3.HasIntersection(aM1))
{
theDI << "Error: method 'HasIntersection' failed.";
}
}
}
// ===================== Test methods of DataMap type =========================
@ -671,7 +695,7 @@ static Standard_Integer QANColTestMap(Draw_Interpretor& di, Standard_Integer arg
return 1;
}
QANCollection_MapFunc aMap;
TestMap(aMap);
TestMap(aMap, di);
return 0;
}

1
tests/collections/grids.list Executable file
View File

@ -0,0 +1 @@
001 n

View File

@ -0,0 +1 @@
pload QAcommands

1
tests/collections/n/end Normal file
View File

@ -0,0 +1 @@
puts "TEST COMPLETED"

3
tests/collections/n/map Normal file
View File

@ -0,0 +1,3 @@
puts "Check NCollection_Map functionality"
QANColTestMap