Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Koch
dune-common
Commits
2c09c636
Commit
2c09c636
authored
19 years ago
by
Markus Blatt
Browse files
Options
Downloads
Patches
Plain Diff
Worte test for SLListModifier and debugged it.
[[Imported from SVN: r1857]]
parent
a8c22a12
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/sllist.hh
+61
-29
61 additions, 29 deletions
common/sllist.hh
common/test/sllisttest.cc
+61
-41
61 additions, 41 deletions
common/test/sllisttest.cc
with
122 additions
and
70 deletions
common/sllist.hh
+
61
−
29
View file @
2c09c636
...
...
@@ -245,6 +245,7 @@ namespace Dune
class
SLListIterator
:
public
Dune
::
ForwardIteratorFacade
<
SLListIterator
<
T
,
A
>
,
T
,
T
&
,
std
::
size_t
>
{
friend
class
SLListConstIterator
<
T
,
A
>
;
friend
class
SLListModifyIterator
<
T
,
A
>
;
friend
class
SLList
<
T
,
A
>
;
public:
...
...
@@ -258,7 +259,7 @@ namespace Dune
{}
inline
SLListIterator
(
const
SLListModifyIterator
<
T
,
A
>&
other
)
:
current_
(
other
.
iterator_
.
current_
)
:
current_
(
other
.
iterator_
.
current_
)
,
list_
(
other
.
iterator_
.
list_
)
{}
/**
...
...
@@ -280,7 +281,6 @@ namespace Dune
return
current_
==
other
.
current_
;
}
/**
* @brief Equality test for the iterator facade.
* @param other The other iterator to check.
...
...
@@ -291,6 +291,16 @@ namespace Dune
return
current_
==
other
.
current_
;
}
/**
* @brief Equality test for the iterator facade.
* @param other The other iterator to check.
* @return true If the other iterator is at the same position.
*/
inline
bool
equals
(
const
SLListModifyIterator
<
T
,
A
>&
other
)
const
{
return
current_
==
other
.
iterator_
.
current_
;
}
/**
* @brief Increment function for the iterator facade.
*/
...
...
@@ -367,6 +377,10 @@ namespace Dune
:
current_
(
other
.
current_
)
{}
inline
SLListConstIterator
(
const
SLListConstIterator
<
T
,
A
>&
other
)
:
current_
(
other
.
current_
)
{}
inline
SLListConstIterator
(
const
SLListModifyIterator
<
T
,
A
>&
other
)
:
current_
(
other
.
iterator_
.
current_
)
{}
...
...
@@ -390,27 +404,6 @@ namespace Dune
return
current_
==
other
.
current_
;
}
/**
* @brief Equality test for the iterator facade.
* @param other The other iterator to check.
* @return true If the other iterator is at the same position.
*/
inline
bool
equals
(
const
SLListModifyIterator
<
T
,
A
>&
other
)
const
{
return
current_
==
other
.
iterator_
.
current_
;
}
/**
* @brief Equality test for the iterator facade.
* @param other The other iterator to check.
* @return true If the other iterator is at the same position.
*/
inline
bool
equals
(
const
SLListIterator
<
T
,
A
>&
other
)
const
{
return
current_
==
other
.
current_
;
}
/**
* @brief Increment function for the iterator facade.
*/
...
...
@@ -428,16 +421,20 @@ namespace Dune
* @brief A mutable iterator for the SLList.
*/
template
<
typename
T
,
class
A
>
class
SLListModifyIterator
:
public
Dune
::
ForwardIteratorFacade
<
SLListIterator
<
T
,
A
>
,
T
,
T
&
,
std
::
size_t
>
class
SLListModifyIterator
:
public
Dune
::
ForwardIteratorFacade
<
SLList
Modify
Iterator
<
T
,
A
>
,
T
,
T
&
,
std
::
size_t
>
{
friend
class
SLListConstIterator
<
T
,
A
>
;
friend
class
SLListIterator
<
T
,
A
>
;
public:
inline
SLListModifyIterator
(
SLListIterator
<
T
,
A
>
beforeIterator
,
SLList
Const
Iterator
<
T
,
A
>
_iterator
)
SLListIterator
<
T
,
A
>
_iterator
)
:
beforeIterator_
(
beforeIterator
),
iterator_
(
_iterator
)
{}
inline
SLListModifyIterator
(
const
SLListModifyIterator
<
T
,
A
>&
other
)
:
beforeIterator_
(
other
.
beforeIterator_
),
iterator_
(
other
.
iterator_
)
{}
inline
SLListModifyIterator
()
:
beforeIterator_
(),
iterator_
()
{}
...
...
@@ -448,7 +445,39 @@ namespace Dune
*/
inline
T
&
dereference
()
const
{
return
iterator_
.
dereference
();
return
*
iterator_
;
}
/**
* @brief Test whether another iterator is equal.
* @return true if the other iterator is at the same position as
* this one.
*/
inline
bool
equals
(
const
SLListConstIterator
<
T
,
A
>&
other
)
const
{
return
iterator_
==
other
;
}
/**
* @brief Test whether another iterator is equal.
* @return true if the other iterator is at the same position as
* this one.
*/
inline
bool
equals
(
const
SLListIterator
<
T
,
A
>&
other
)
const
{
return
iterator_
==
other
;
}
/**
* @brief Test whether another iterator is equal.
* @return true if the other iterator is at the same position as
* this one.
*/
inline
bool
equals
(
const
SLListModifyIterator
<
T
,
A
>&
other
)
const
{
return
iterator_
==
other
.
iterator_
;
}
/**
...
...
@@ -465,7 +494,10 @@ namespace Dune
*
* Starting from the element at the current position all
* elements will be shifted by one position to the back.
* The iterator will point to the same element after the insertion.
* The iterator will point to the same element as before
* after the insertion, i.e the number of increments to
* reach the same position from a begin iterator increases
* by one.
* This means the inserted element is the one before the one
* the iterator points to.
* @param v The value to insert.
...
...
@@ -493,7 +525,7 @@ namespace Dune
/** @brief Iterator positioned at the position before the current. */
SLListIterator
<
T
,
A
>
beforeIterator_
;
/** @brief Iterator positioned at the current position. */
SLList
Const
Iterator
<
T
,
A
>
iterator_
;
SLListIterator
<
T
,
A
>
iterator_
;
};
template
<
typename
T
,
class
A
>
SLList
<
T
,
A
>::
Element
::
Element
(
const
T
&
item
)
...
...
@@ -626,7 +658,7 @@ namespace Dune
template
<
typename
T
,
class
A
>
inline
SLListModifyIterator
<
T
,
A
>
SLList
<
T
,
A
>::
endModify
()
{
return
SLListModifyIterator
<
T
,
A
>
(
tail
(),
end
());
return
SLListModifyIterator
<
T
,
A
>
(
iterator
(
tail_
,
this
),
iterator
());
}
...
...
This diff is collapsed.
Click to expand it.
common/test/sllisttest.cc
+
61
−
41
View file @
2c09c636
...
...
@@ -50,7 +50,7 @@ void randomizeListFront(Dune::SLList<T,A>& alist){
alist
.
push_back
((
range
*
(
rand
()
/
(
RAND_MAX
+
1.0
))));
}
int
testDelete
Next
()
int
testDelete
()
{
typedef
Dune
::
SLList
<
int
,
Dune
::
PoolAllocator
<
int
,
8
*
1024
-
16
>
>
List
;
List
alist
;
...
...
@@ -59,82 +59,86 @@ int testDeleteNext()
alist
.
push_back
(
4
);
alist
.
push_back
(
5
);
List
::
iterator
iter
=
alist
.
oneBeforeBegin
();
iter
.
deleteNext
();
List
::
iterator
iter1
=
iter
;
++
iter1
;
List
::
ModifyIterator
iter
=
alist
.
beginModify
();
iter
.
remove
();
if
(
*
(
alist
.
begin
())
!=
4
)
{
std
::
cerr
<<
"delete next on position before head failed!
"
<<
std
::
endl
;
std
::
cerr
<<
"delete next on position before head failed!
"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
return
1
;
}
if
(
*
iter
1
!=
4
)
{
std
::
cerr
<<
"delete next failed
"
<<
std
::
endl
;
if
(
*
iter
!=
4
)
{
std
::
cerr
<<
"delete next failed
! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
return
1
;
}
++
iter
;
iter
.
deleteNext
();
++
iter
;
iter
.
remove
();
if
(
iter
!=
alist
.
end
())
{
std
::
cerr
<<
"delete next faild
"
<<
std
::
endl
;
std
::
cerr
<<
"delete next faild
! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
return
1
;
}
if
(
*
(
alist
.
tail
())
!=
4
)
{
std
::
cerr
<<
"delete before tail did not change tail!
"
<<
std
::
endl
;
std
::
cerr
<<
"delete before tail did not change tail!
"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
}
return
0
;
}
int
testInsert
After
()
int
testInsert
()
{
typedef
Dune
::
SLList
<
int
,
Dune
::
PoolAllocator
<
int
,
8
*
1024
-
16
>
>
List
;
List
alist
;
alist
.
push_back
(
3
);
List
::
i
terator
iter
=
alist
.
begin
();
iter
.
insert
After
(
5
);
List
::
ModifyI
terator
iter
=
alist
.
begin
Modify
();
iter
.
insert
(
7
);
int
ret
=
0
;
if
(
*
iter
!=
3
)
{
std
::
cerr
<<
"Value at current position changed due to insert
After"
<<
std
::
endl
;
std
::
cerr
<<
"Value at current position changed due to insert
! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
ret
++
;
}
++
iter
;
if
(
iter
==
alist
.
end
()
||
*
iter
!=
5
)
{
std
::
cerr
<<
"Insert
ion failed!"
<<
std
::
endl
;
++
ret
;
if
(
*
alist
.
begin
()
!=
7
)
{
std
::
cerr
<<
"Insert
did not change first element! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
ret
++
;
}
iter
=
alist
.
oneBeforeBegin
();
iter
.
insert
After
(
5
);
++
iter
;
if
(
iter
==
alist
.
end
()
||
*
iter
!=
5
)
{
std
::
cerr
<<
"Insertion failed
!"
<<
std
::
endl
;
iter
=
alist
.
beginModify
();
iter
.
insert
(
5
);
if
(
iter
==
alist
.
end
()
||
*
iter
!=
7
)
{
std
::
cerr
<<
"Insertion failed
.! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
++
ret
;
}
if
(
*
(
alist
.
begin
())
!=
5
)
{
std
::
cerr
<<
"Insert after at onebeforeBegin did not change head!
"
<<
std
::
endl
;
std
::
cerr
<<
"Insert after at onebeforeBegin did not change head!
"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
++
ret
;
}
iter
=
alist
.
tail
();
iter
.
insertAfter
(
20
);
++
iter
;
if
(
iter
==
alist
.
end
()
||
*
iter
!=
20
)
{
std
::
cerr
<<
"Insertion failed!"
<<
std
::
endl
;
iter
=
alist
.
endModify
();
if
(
iter
!=
alist
.
end
())
{
std
::
cerr
<<
" Iterator got by endModify does not equal that got by end()! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
++
ret
;
}
iter
.
insert
(
20
);
if
(
iter
!=
alist
.
end
())
{
std
::
cerr
<<
"Insertion changed end iterator! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
++
ret
;
}
if
(
*
(
alist
.
tail
())
!=
20
)
{
std
::
cerr
<<
"tail was not changed!!
"
<<
std
::
endl
;
std
::
cerr
<<
"tail was not changed!!
"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
++
ret
;
}
alist
.
clear
();
iter
=
alist
.
oneBeforeBegin
();
iter
.
insertAfter
(
5
);
++
iter
;
if
(
iter
==
alist
.
end
()
||
*
iter
!=
5
)
{
std
::
cerr
<<
"Insertion failed!"
<<
std
::
endl
;
iter
=
alist
.
beginModify
();
iter
.
insert
(
5
);
if
(
iter
!=
alist
.
end
())
{
std
::
cerr
<<
"Insertion failed! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
++
ret
;
}
return
ret
;
...
...
@@ -152,11 +156,11 @@ int testOneBeforeBegin(T& alist)
++
citerBefore
;
if
(
iterBefore
!=
iter
||
&
(
*
iterBefore
)
!=
&
(
*
iter
))
{
std
::
cerr
<<
"one before iterator incremented once should point to begin()
"
<<
std
::
endl
;
std
::
cerr
<<
"one before iterator incremented once should point to begin()
! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
ret
++
;
}
if
(
citerBefore
!=
iter
||
&
(
*
citerBefore
)
!=
&
(
*
iter
))
{
std
::
cerr
<<
"one before iterator incremented once should point to begin()
"
<<
std
::
endl
;
std
::
cerr
<<
"one before iterator incremented once should point to begin()
! "
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
ret
++
;
}
return
ret
;
...
...
@@ -212,13 +216,29 @@ int main()
randomizeListFront
(
list
);
randomizeListFront
(
list2
);
Printer
<
std
::
iterator_traits
<
Dune
::
SLList
<
double
>::
ModifyIterator
>::
value_type
>
print
;
Dune
::
SLList
<
double
>::
ModifyIterator
lbegin
=
list
.
beginModify
(),
lend
=
list
.
endModify
();
double
&
d
=
lbegin
.
dereference
();
d
=
2.0
;
double
&
d1
=
lbegin
.
dereference
();
lbegin
.
dereference
()
=
5.0
;
lbegin
.
operator
*
()
=
5.0
;
*
lbegin
=
5.0
;
ret
+=
testConstIterator
(
lbegin
,
lend
,
print
);
ret
+=
testIterator
(
list
);
ret
+=
testIterator
(
list1
);
ret
+=
testPushPop
();
ret
+=
testOneBeforeBegin
(
list1
);
ret
+=
testInsert
After
();
ret
+=
testDelete
Next
();
ret
+=
testInsert
();
ret
+=
testDelete
();
list
.
clear
();
list1
.
clear
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment