-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Turned the primes document into an embedded resource. #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cuckoo Hashtable unit test is failing due to the PrimesList.cs
not being able to parse the file. Please make sure your rebase your branch against upstream/master and ensure that all unit tests are passing.
Error Message:
System.FormatException : Input string was not in a correct format.
Stack Trace:
at System.Number.StringToNumber(ReadOnlySpan`1 str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at DataStructures.Common.PrimesList.<>c.<_initializeData>b__7_1(String item) in /home/travis/build/aalhour/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 80
at System.Linq.Enumerable.SelectListIterator`2.ToList()
at DataStructures.Common.PrimesList._initializeData() in /home/travis/build/aalhour/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 80
at DataStructures.Common.PrimesList.get_Instance() in /home/travis/build/aalhour/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 53
at DataStructures.Dictionaries.CuckooHashTable`2..ctor() in /home/travis/build/aalhour/C-Sharp-Algorithms/DataStructures/Dictionaries/CuckooHashTable.cs:line 49
at UnitTest.DataStructuresTests.CuckooHashTableTest.DoTest() in /home/travis/build/aalhour/C-Sharp-Algorithms/UnitTest/DataStructuresTests/CuckooHashTableTest.cs:line 11
There's a problem with the double-check locking implementation. Checking it now. |
There's obviously a problem with the format of the embedded file but so far it's not straightforward to find what that is through Travis (works fine on my PC). There's, however, another issue that happens when multiple instances access PrimesList.Instance and it doesn't happen all the time - however, I've managed to successfully simulate it and I've sent a commit into this PR. I'll try to think of a way to solve the original issue and then see what should be included in this PR and what shouldn't. I'm 0 commits behind master btw. |
Doesn't work on my machine though. Here's how to reproduce: # Checkout upstream/master
git clone https://github.com/aalhour/C-Sharp-Algorithms.git
cd C-Sharp-Algorithms
# Get your changes into a branch checked out from upstream/master
git checkout -b nickntg-master master
git pull https://github.com/nickntg/C-Sharp-Algorithms.git master
# Build and run
dotnet build --configuration Release
dotnet test Here is the output I got: ➜ dotnet build --configuration Release
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 28.04 ms for /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/Algorithms/Algorithms.csproj.
Restore completed in 28.06 ms for /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/DataStructures.csproj.
Restore completed in 59.7 ms for /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/UnitTest/UnitTest.csproj.
Restore completed in 31.44 ms for /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/UnitTest/UnitTest.csproj.
DataStructures -> /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/bin/Release/netcoreapp2.0/DataStructures.dll
Algorithms -> /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/Algorithms/bin/Release/netcoreapp2.0/Algorithms.dll
UnitTest -> /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/UnitTest/bin/Release/netcoreapp2.0/UnitTest.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.18 ➜ dotnet test
Test run for /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/UnitTest/bin/Debug/netcoreapp2.0/UnitTest.dll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
(a)(s)(z)(x)(d)(c)(f)(v)(a)(z)(s)(x)(c)(v)(f)(d)(f)(c)(d)(v)(s)(x)(a)(z)Walk the graph using DFS from F:
[xUnit.net 00:00:02.08] UnitTest.DataStructuresTests.CuckooHashTableTest.DoTest [FAIL]
X UnitTest.DataStructuresTests.CuckooHashTableTest.DoTest [58ms]
Error Message:
System.FormatException : Input string was not in a correct format.
Stack Trace:
at System.Number.StringToNumber(ReadOnlySpan`1 str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at DataStructures.Common.PrimesList.<>c.<_initializeData>b__7_1(String item) in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 80
at System.Linq.Enumerable.SelectListIterator`2.ToList()
at DataStructures.Common.PrimesList._initializeData() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 80
at DataStructures.Common.PrimesList.get_Instance() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 52
at DataStructures.Dictionaries.CuckooHashTable`2..ctor() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Dictionaries/CuckooHashTable.cs:line 49
at UnitTest.DataStructuresTests.CuckooHashTableTest.DoTest() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/UnitTest/DataStructuresTests/CuckooHashTableTest.cs:line 11
Test run in progress.Remove At 4:
[0] => fst
[1] => sec
[2] => trd
[3] => for
[4] => sxt
[5] => svn
[6] => egt
(d) (x) (f) (c) (s) (d) (v) (a) (z)
[xUnit.net 00:00:02.16] UnitTest.DataStructuresTests.PrimeListTest.DoTest [FAIL]
X UnitTest.DataStructuresTests.PrimeListTest.DoTest [9ms]
Error Message:
System.FormatException : Input string was not in a correct format.
Stack Trace:
at System.Number.StringToNumber(ReadOnlySpan`1 str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(ReadOnlySpan`1 s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at DataStructures.Common.PrimesList.<>c.<_initializeData>b__7_1(String item) in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 80
at System.Linq.Enumerable.SelectListIterator`2.ToList()
at DataStructures.Common.PrimesList._initializeData() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 80
at DataStructures.Common.PrimesList.get_Instance() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/DataStructures/Common/PrimesList.cs:line 52
at UnitTest.DataStructuresTests.PrimeListTest.DoTest() in /Users/ahmad/PersonalWorkspace/C-Sharp-Algorithms/UnitTest/DataStructuresTests/PrimeListTest.cs:line 11
Test run in progress.Is there an edge from f to c? True. If yes it's weight is: 1.
After removing edges (d-c), (c-v), (a-z):
a: [s(1), x(3)]
z: []
s: [a(1), x(3), d(3)]
x: [s(3), d(1), c(2), a(3)]
d: [x(1), f(1), s(3)]
c: [x(2), f(1)]
f: [d(1), c(1), v(1)]
v: [f(1)]
(a)(s)(x)(z)(d)(c)(f)(v)(a)(z)(x)(c)(v)(f)(d)(s)(f)(d)(c)(v)(s)(x)(a)(z)
(f)(v)(c)(d)(x)(a)(z)(s)(a)(s)(z)(x)(d)(c)(f)(v)(a)(z)(s)(x)(c)(v)(f)(d)Walk the graph using BFS from F:
Test Run Failed.
Total tests: 171
Passed: 169
Failed: 2
Total time: 3.9706 Seconds The above output matches the output of the Travis build, btw. |
Done that. Here's the output from two consecutive runs of dotnet test.
Perplexed yet? |
@nickntg - What is your OS and IDE? |
@aalhour Windows 10 with VS 2017. |
That's why, there is a different "Format CultureInfo" between the Operating Systems. I get errors on my machine (mac OS) and the tests fail on Travis CI (Ubuntu), can you try implementing a CultureInfo to parse the file? |
@aalhour It's not culture info (it's all straight integers anyway - were it for decimals, a CultureInfo.InvariantCulture parameter would be needed on Split()). It's the line splitting that seems to not work as expected with the embedded resource. Still trying to understand why, since it seemed to be working with the file. I can revert all commits or submit a new, cleaner PR. There still is a separate issue with the double-null check pattern that is lurking around. What do you want me to do? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This might help to get started with the embedded resource issue (see #123 ).