Skip to content

Commit

Permalink
Fixed string constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 21, 2023
1 parent 90c2681 commit 8da4b87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Pgvector/Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Vector(ReadOnlyMemory<float> v)
=> Memory = v;

public Vector(string s)
=> new Vector(Array.ConvertAll(s.Substring(1, s.Length - 2).Split(','), v => float.Parse(v, CultureInfo.InvariantCulture)));
=> Memory = Array.ConvertAll(s.Substring(1, s.Length - 2).Split(','), v => float.Parse(v, CultureInfo.InvariantCulture));

public override string ToString()
=> string.Concat("[", string.Join(",", Memory.ToArray().Select(v => v.ToString(CultureInfo.InvariantCulture))), "]");
Expand Down
7 changes: 7 additions & 0 deletions tests/Pgvector.Tests/VectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ namespace Pgvector.Tests;

public class VectorTests
{
[Fact]
public void StringConstructor()
{
var v = new Vector("[1,2,3]");
Assert.Equal("[1,2,3]", v.ToString());
}

[Fact]
public void Equal()
{
Expand Down

0 comments on commit 8da4b87

Please sign in to comment.