Skip to content

Commit

Permalink
Added LogNot
Browse files Browse the repository at this point in the history
  • Loading branch information
kev committed Jan 22, 2024
1 parent 636519b commit dd1b2c0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CLVMDotNet/src/CLVM/MoreOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,13 @@ public static Tuple<BigInteger, SExp> OpAll(SExp args)
return Tuple.Create(cost, r);
}


public static Tuple<BigInteger, SExp> OpLogNot(dynamic args)
{
throw new Exception("Not implemented yet!");
var list = ArgsAsIntList("lognot", args, 1);
BigInteger cost = Costs.LOGNOT_BASE_COST + list[0].Item2 * Costs.LOGNOT_COST_PER_BYTE;
BigInteger s = list[0].Item1;
var inverted = -s - 1;
return MallocCost(cost, SExp.To(inverted));
}

public static Tuple<BigInteger, SExp> OpNot(dynamic args)
Expand Down
33 changes: 33 additions & 0 deletions CLVMDotNet/tests/CLVM/Operators/OperatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,39 @@ public void OpLogxorInt()
#endregion

#region OpLogNot
[Fact]
public void OpLogNot()
{
var result = x.Operator.ApplyOperator(new byte[] { 0x1B }, x.SExp.To(new List<int> { 1}));
var atom = result.Item2.AsAtom();
Assert.Equal(344, result.Item1);
Assert.True(atom!.SequenceEqual(new byte[]
{
0xFE
}));
}

[Fact]
public void OpLogNotNegativeNumbers()
{
var result = x.Operator.ApplyOperator(new byte[] { 0x1B }, x.SExp.To(new List<BigInteger> { -1111}));
var atom = result.Item2.AsAtom();
Assert.Equal(357, result.Item1);
Assert.True(atom!.SequenceEqual(new byte[]
{
0x04, 0x56
}));
}

[Fact]
public void OpLogNotThrowsWithNoParameters()
{
var errorMessage =
Assert.Throws<x.EvalError>(() =>
x.Operator.ApplyOperator(new byte[] { 0x1B },
x.SExp.To(new List<int> { })));
Assert.Contains("lognot takes exactly 1 arguments", errorMessage.Message);
}
#endregion

#region OpAny
Expand Down

0 comments on commit dd1b2c0

Please sign in to comment.