-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
338 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
using System.Threading; | ||
|
||
using JetBrains.Annotations; | ||
|
||
using static CodeJam.Arithmetic.OperatorsFactory; | ||
|
||
namespace CodeJam.Arithmetic | ||
{ | ||
partial class Operators<T> | ||
{ | ||
private static readonly Lazy<Func<T, T, T>> _plus | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.Add), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// Plus operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> Plus => _plus.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _minus | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.Subtract), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// Minus operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> Minus => _minus.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _mul | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.Multiply), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// Mul operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> Mul => _mul.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _div | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.Divide), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// Div operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> Div => _div.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _modulo | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.Modulo), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// Modulo operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> Modulo => _modulo.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _xor | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.ExclusiveOr), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// Xor operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> Xor => _xor.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _bitwiseand | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.And), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// BitwiseAnd operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> BitwiseAnd => _bitwiseand.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _bitwiseor | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.Or), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// BitwiseOr operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> BitwiseOr => _bitwiseor.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _leftshift | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.LeftShift), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// LeftShift operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> LeftShift => _leftshift.Value; | ||
|
||
private static readonly Lazy<Func<T, T, T>> _rightshift | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.RightShift), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// RightShift operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> RightShift => _rightshift.Value; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<#@ template debug="false" hostspecific="false" language="C#" #> | ||
<#@ assembly name="System.Core" | ||
#><#@ include file="Operators.ttinclude" | ||
#><#@ import namespace="System.Linq" #> | ||
<#@ import namespace="System.Text" #> | ||
<#@ import namespace="System.Collections.Generic" #> | ||
<#@ import namespace="System.Linq.Expressions" #> | ||
<#@ output extension=".generated.cs" | ||
#>//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System; | ||
using System.Linq.Expressions; | ||
using System.Threading; | ||
|
||
using JetBrains.Annotations; | ||
|
||
using static CodeJam.Arithmetic.OperatorsFactory; | ||
|
||
namespace CodeJam.Arithmetic | ||
{ | ||
partial class Operators<T> | ||
{ | ||
<#foreach (var op in ops) {#> | ||
private static readonly Lazy<Func<T, T, T>> _<#=op.Name.ToLower()#> | ||
= new Lazy<Func<T, T, T>>(() => CreateNumOperFunc<T>(ExpressionType.<#=op.Type#>), LazyThreadSafetyMode.PublicationOnly); | ||
|
||
/// <summary> | ||
/// <#=op.Name#> operator. | ||
/// </summary> | ||
[NotNull] | ||
public static Func<T, T, T> <#=op.Name#> => _<#=op.Name.ToLower()#>.Value; | ||
|
||
<#}#> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<#@ template debug="false" hostspecific="false" language="C#" #> | ||
<#@ assembly name="System.Core" #> | ||
<#@ import namespace="System.Linq" #> | ||
<#@ import namespace="System.Text" #> | ||
<#@ import namespace="System.Collections.Generic" #> | ||
<#@ import namespace="System.Linq.Expressions" #> | ||
<# | ||
var ops = | ||
new [] | ||
{ | ||
new OpInfo("Plus", "+", ExpressionType.Add, false), | ||
new OpInfo("Minus", "-", ExpressionType.Subtract, false), | ||
new OpInfo("Mul", "*", ExpressionType.Multiply, false), | ||
new OpInfo("Div", "/", ExpressionType.Divide, false), | ||
new OpInfo("Modulo", "%", ExpressionType.Modulo, true), | ||
new OpInfo("Xor", "^", ExpressionType.ExclusiveOr, true), | ||
new OpInfo("BitwiseAnd", "&", ExpressionType.And, true), | ||
new OpInfo("BitwiseOr", "|", ExpressionType.Or, true), | ||
new OpInfo("LeftShift", "<<", ExpressionType.LeftShift, true), | ||
new OpInfo("RightShift", ">>", ExpressionType.RightShift, true), | ||
}; | ||
#> | ||
<#+ | ||
private class OpInfo | ||
{ | ||
public string Name { get; } | ||
public string Sign { get; } | ||
public ExpressionType Type { get; } | ||
public bool IntOnly { get; } | ||
public OpInfo(string name, string sign, ExpressionType type, bool intOnly) | ||
{ | ||
Name = name; | ||
Type = type; | ||
Sign = sign; | ||
IntOnly = intOnly; | ||
} | ||
} | ||
#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
Main/tests-performance/Arithmetic/OperatorsGreaterThanOrEqualPerformanceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
Main/tests-performance/Arithmetic/OperatorsLessThanPerformanceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
using NUnit.Framework; | ||
|
||
using IntOp = CodeJam.Arithmetic.Operators<int>; | ||
using NullableDoubleOp = CodeJam.Arithmetic.Operators<double?>; | ||
|
||
namespace CodeJam.Arithmetic | ||
{ | ||
partial class OperatorsTest | ||
{ | ||
[Test] | ||
public void IntPlus() => Assert.AreEqual(1 + 2, IntOp.Plus(1, 2)); | ||
|
||
[Test] | ||
public void NullableDoublePlus() => Assert.AreEqual(1f + 2f, NullableDoubleOp.Plus(1, 2)); | ||
|
||
[Test] | ||
public void IntMinus() => Assert.AreEqual(1 - 2, IntOp.Minus(1, 2)); | ||
|
||
[Test] | ||
public void NullableDoubleMinus() => Assert.AreEqual(1f - 2f, NullableDoubleOp.Minus(1, 2)); | ||
|
||
[Test] | ||
public void IntMul() => Assert.AreEqual(1 * 2, IntOp.Mul(1, 2)); | ||
|
||
[Test] | ||
public void NullableDoubleMul() => Assert.AreEqual(1f * 2f, NullableDoubleOp.Mul(1, 2)); | ||
|
||
[Test] | ||
public void IntDiv() => Assert.AreEqual(1 / 2, IntOp.Div(1, 2)); | ||
|
||
[Test] | ||
public void NullableDoubleDiv() => Assert.AreEqual(1f / 2f, NullableDoubleOp.Div(1, 2)); | ||
|
||
[Test] | ||
public void IntModulo() => Assert.AreEqual(1 % 2, IntOp.Modulo(1, 2)); | ||
|
||
[Test] | ||
public void IntXor() => Assert.AreEqual(1 ^ 2, IntOp.Xor(1, 2)); | ||
|
||
[Test] | ||
public void IntBitwiseAnd() => Assert.AreEqual(1 & 2, IntOp.BitwiseAnd(1, 2)); | ||
|
||
[Test] | ||
public void IntBitwiseOr() => Assert.AreEqual(1 | 2, IntOp.BitwiseOr(1, 2)); | ||
|
||
[Test] | ||
public void IntLeftShift() => Assert.AreEqual(1 << 2, IntOp.LeftShift(1, 2)); | ||
|
||
[Test] | ||
public void IntRightShift() => Assert.AreEqual(1 >> 2, IntOp.RightShift(1, 2)); | ||
|
||
} | ||
} |
Oops, something went wrong.