Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dunixir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
teaching
dunixir
Commits
43871078
Commit
43871078
authored
3 years ago
by
ROUSSET Noemie
Browse files
Options
Downloads
Patches
Plain Diff
correction of implementation of BR_G73 code + tests
parent
8ba8198f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/local_augmentation_example.ex
+9
-3
9 additions, 3 deletions
lib/local_augmentation_example.ex
test/identity/augmentation/identity_user_id_unique_test.exs
+76
-41
76 additions, 41 deletions
test/identity/augmentation/identity_user_id_unique_test.exs
with
85 additions
and
44 deletions
lib/local_augmentation_example.ex
+
9
−
3
View file @
43871078
...
...
@@ -373,9 +373,15 @@ defmodule Index.Augmentation do
end
## BR_G73
def
identityUserIdUnicity
(
local_iindex
,
key
)
do
[{
_key
,
entry
}]
=
:ets
.
lookup
(
local_iindex
,
key
)
entry
.
uidUnique
==
true
def
identityUserIdUnicity
(
local_iindex
)
do
:ets
.
match
(
local_iindex
,
{
:_
,
:"$1"
})
|>
Enum
.
reduce
(
true
,
fn
[
entry
],
acc
->
if
entry
[
:uidUnique
]
!=
nil
do
(
entry
[
:uidUnique
]
==
true
)
&&
acc
else
acc
end
end
)
end
## BR_G74
...
...
This diff is collapsed.
Click to expand it.
test/identity/augmentation/identity_user_id_unique_test.exs
+
76
−
41
View file @
43871078
defmodule
IdentityUserIdUnicityTest
do
use
ExUnit
.
Case
@identUserIdUnique
%{
op:
'CREATE'
,
uid:
"tic"
,
pub:
"5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH"
,
created_on:
"7543-000044410C5370DE8DBA911A358F318096B7A269CFC2BB93272E397CC513EA0A"
,
written_on:
"167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5E99038"
,
member:
true
,
wasMember:
true
,
kick:
false
,
uidUnique:
true
}
@identUserIdNonUnique
%{
op:
'CREATE'
,
uid:
"tac"
,
pub:
"5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH"
,
created_on:
"7543-000044410C5370DE8DBA911A358F318096B7A269CFC2BB93272E397CC513EA0A"
,
written_on:
"167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5E99038"
,
member:
true
,
wasMember:
true
,
kick:
false
,
uidUnique:
false
}
@identUserIdWithoutField
%{
op:
'CREATE'
,
uid:
"tac"
,
pub:
"5B8iMAzq1dNmFe3ZxFTBQkqhq4fsztg1gZvxHXCk1XYH"
,
created_on:
"7543-000044410C5370DE8DBA911A358F318096B7A269CFC2BB93272E397CC513EA0A"
,
written_on:
"167884-0001DFCA28002A8C96575E53B8CEF8317453A7B0BA255542CCF0EC8AB5E99038"
,
member:
true
,
wasMember:
true
,
kick:
false
}
doctest
Index
.
Augmentation
.
IIndex
setup_all
do
local_iindex_a
=
:ets
.
new
(
:local_iindex
,
[
:set
,
:protected
])
local_iindex_b
=
:ets
.
new
(
:local_iindex
,
[
:set
,
:protected
])
local_mindex_a
=
:ets
.
new
(
:local_mindex
,
[
:set
,
:protected
])
local_mindex_b
=
:ets
.
new
(
:local_mindex
,
[
:set
,
:protected
])
Index
.
Generation
.
add_identity
(
"blockstamp_test"
,
local_iindex_a
,
local_mindex_a
,
%{
"pub"
=>
"pub_toto"
,
"block_uid"
=>
"block_uid_test"
,
"user_id"
=>
"user_id_test"
})
Index
.
Generation
.
add_identity
(
"blockstamp_test"
,
local_iindex_b
,
local_mindex_b
,
%{
"pub"
=>
"pub_toto"
,
"block_uid"
=>
"block_uid_test"
,
"user_id"
=>
"user_id_test"
})
{
:ok
,
global_iindex_a
}
=
:dets
.
open_file
(
:global_iindex_a
,
type:
:set
)
{
:ok
,
global_iindex_b
}
=
:dets
.
open_file
(
:global_iindex_b
,
type:
:set
)
:ets
.
to_dets
(
local_iindex_a
,
:global_iindex_a
)
:ets
.
to_dets
(
local_iindex_b
,
:global_iindex_b
)
[{
"pub_toto"
,
elt
}]
=
:dets
.
lookup
(
:global_iindex_b
,
"pub_toto"
)
new_elt
=
Map
.
replace!
(
elt
,
:uid
,
"user_id_test_2"
)
:dets
.
insert
(
:global_iindex_b
,
{
"pub_toto"
,
new_elt
})
Index
.
Augmentation
.
IIndex
.
uidUnique
(
local_iindex_a
,
global_iindex_a
,
"pub_toto"
)
Index
.
Augmentation
.
IIndex
.
uidUnique
(
local_iindex_b
,
global_iindex_b
,
"pub_toto"
)
identityUserIdUnicityTrue
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex_b
,
"pub_toto"
)
identityUserIdUnicityFalse
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex_a
,
"pub_toto"
)
:dets
.
close
(
global_iindex_a
)
:file
.
delete
(
"global_iindex_a"
)
:dets
.
close
(
global_iindex_b
)
:file
.
delete
(
"global_iindex_b"
)
{
:ok
,
identityUserIdUnicityTrue:
identityUserIdUnicityTrue
,
identityUserIdUnicityFalse:
identityUserIdUnicityFalse
}
#test with a uid unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identUserIdUnique
})
userIdUniqueOneElt
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#test with a uid unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identUserIdWithoutField
})
userIdUniqueOneEltWithoutField
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#test with a uid unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identUserIdWithoutField
})
:ets
.
insert
(
local_iindex
,
{
1
,
@identUserIdUnique
})
userIdUniqueManyElt
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#test with a uid non unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identUserIdNonUnique
})
userIdNonUniqueOneElt
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
#test with a uid non unique
local_iindex
=
:ets
.
new
(
:"test/local_iindex"
,
[
:set
,
:protected
])
:ets
.
insert
(
local_iindex
,
{
0
,
@identUserIdWithoutField
})
:ets
.
insert
(
local_iindex
,
{
1
,
@identUserIdNonUnique
})
:ets
.
insert
(
local_iindex
,
{
2
,
@identUserIdUnique
})
userIdNonUniqueManyElt
=
Index
.
Augmentation
.
IIndex
.
identityUserIdUnicity
(
local_iindex
)
:file
.
delete
(
"test/local_iindex"
)
{
:ok
,
userIdUniqueOneElt:
userIdUniqueOneElt
,
userIdUniqueOneEltWithoutField:
userIdUniqueOneEltWithoutField
,
userIdUniqueManyElt:
userIdUniqueManyElt
,
userIdNonUniqueOneElt:
userIdNonUniqueOneElt
,
userIdNonUniqueManyElt:
userIdNonUniqueManyElt
}
end
test
"check IdentityUserIdUnicity"
,
state
do
IO
.
puts
(
"uid unique of b :
#{
state
.
identityUserIdUnicityTrue
}
and uid unique of a :
#{
state
.
identityUserIdUnicityFalse
}
"
)
assert
state
.
identityUserIdUnicityTrue
==
true
assert
state
.
identityUserIdUnicityFalse
==
false
assert
state
.
userIdUniqueOneElt
==
true
assert
state
.
userIdUniqueOneEltWithoutField
==
true
assert
state
.
userIdUniqueManyElt
==
true
assert
state
.
userIdNonUniqueOneElt
==
false
assert
state
.
userIdNonUniqueManyElt
==
false
end
end
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