text:
#ifndef TENSORFLOW_CORE_KERNELS_THREADPOOL_DATASET_OP_H_
#define TENSORFLOW_CORE_KERNELS_THREADPOOL_DATASET_OP_H_

#include "tensorflow/core/framework/dataset.h"
#include "tensorflow/core/platform/platform.h"

namespace tensorflow {
namespace data {
namespace experimental {

// TODO(jsimsa): Provide class-level documentation for this and the other ops.
class MaxIntraOpParallelismDatasetOp : public UnaryDatasetOpKernel {
 public:
  static constexpr const char* const kDatasetType =
      "MaxIntraOpParallelismDataset";
  static constexpr const char* const kDatasetOp =
      "MaxIntraOpParallelismDatasetOp";

  // Creates and returns a MaxIntraOpParallelismDatasetOp::Dataset in output,
  // given the input dataset, and max_intra_op_parallelism parameters. This
  // method is used to create the dataset without explicitly using the
  // MaxIntraOpParallelismDatasetOp.
  static void MakeDatasetFromOptions(OpKernelContext* ctx, DatasetBase* input,
                                     int32 max_intra_op_parallelism,
                                     DatasetBase** output);

  explicit MaxIntraOpParallelismDatasetOp(OpKernelConstruction* ctx)
      : UnaryDatasetOpKernel(ctx) {}

 protected:
  void MakeDataset(OpKernelContext* ctx, DatasetBase* input,
                   DatasetBase** output) override;

 private:
  class Dataset;
};

// TODO(jsimsa): Provide class-level documentation for this and the other ops.
class PrivateThreadPoolDatasetOp : public UnaryDatasetOpKernel {
 public:
  static constexpr const char* const kDatasetType = "PrivateThreadPoolDataset";
  static constexpr const char* const kDatasetOp = "PrivateThreadPoolDatasetOp";

  // Creates and returns a PrivateThreadPoolDatasetOp::Dataset in output, given
  // the input and number of threads. This method is used to create the dataset
  // without explicitly using the PrivateThreadPoolDatasetOp.
  static void MakeDatasetFromOptions(OpKernelContext* ctx, DatasetBase* input,
                                     int32 num_threads, DatasetBase** output);

  explicit PrivateThreadPoolDatasetOp(OpKernelConstruction* ctx)
      : UnaryDatasetOpKernel(ctx) {}

 protected:
  void MakeDataset(OpKernelContext* ctx, DatasetBase* input,
                   DatasetBase** output) override;

 private:
  class Dataset;
};

}  // namespace experimental
}  // namespace data
}  // namespace tensorflow

#endif  // TENSORFLOW_CORE_KERNELS_THREADPOOL_DATASET_OP_H_


text:
<resources>
    <string name="app_name">TIM_PHP</string>
    <string name="permDesc">TIM signature permission mandatory</string>
    <string name="permLabel">TIM signature permission</string>
</resources>

redpajama_set_name: RedPajamaGithub


text:
var socket = new WebSocket("ws://localhost:8080/TutoWebSocket/tuto");

socket.onmessage = function(event){
	console.dir(event);
	console.log(event.data);
	var data = JSON.parse(event.data);
	console.dir(data);
	console.log(data.c);
	console.log(data.d);
};

setTimeout(function(){
	var data = {
		a : 100,
		b : "coucou"
	};
    socket.send(JSON.stringify(data));
},1000);


text:
package org.w3c.domts.level1.core;

import org.w3c.dom.*;

import org.w3c.domts.DOMTestCase;
import org.w3c.domts.DOMTestDocumentBuilderFactory;

/**
 * The "setNamedItem(arg)" method raises a
 * INUSE_ATTRIBUTE_ERR DOMException if "arg" is an
 * Attr that is already in an attribute of another Element.
 * Create a NamedNodeMap object from the attributes of the
 * last child of the third employee and attempt to add
 * an attribute that is already being used by the first
 * employee.  This should raise the desired exception.
* @author NIST
* @author Mary Brady
* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR'])
* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788
* @see http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-1025163788')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR'])
* @see http://www.w3.org/Bugs/Public/show_bug.cgi?id=249
*/
public final class namednodemapinuseattributeerr extends DOMTestCase {

   /**
    * Constructor.
    * @param factory document factory, may not be null
    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
    */
   public namednodemapinuseattributeerr(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
      super(factory);

    //
    //   check if loaded documents are supported for content type
    //
    String contentType = getContentType();
    preload(contentType, "staff", true);
    }

   /**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
   public void runTest() throws Throwable {
      Document doc;
      NodeList elementList;
      Element firstNode;
      Node testNode;
      NamedNodeMap attributes;
      Attr domesticAttr;
      Attr setAttr;
      Node setNode;
      doc = (Document) load("staff", true);
      elementList = doc.getElementsByTagName("address");
      firstNode = (Element) elementList.item(0);
      domesticAttr = doc.createAttribute("domestic");
      domesticAttr.setValue("Yes");
      setAttr = firstNode.setAttributeNode(domesticAttr);
      elementList = doc.getElementsByTagName("address");
      testNode = elementList.item(2);
      attributes = testNode.getAttributes();

      {
         boolean success = false;
         try {
            setNode = attributes.setNamedItem(domesticAttr);
          } catch (DOMException ex) {
            success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR);
         }
         assertTrue("throw_INUSE_ATTRIBUTE_ERR", success);
      }
}
   /**
    *  Gets URI that identifies the test.
    *  @return uri identifier of test
    */
   public String getTargetURI() {
      return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapinuseattributeerr";
   }
   /**
    * Runs this test from the command line.
    * @param args command line arguments
    */
   public static void main(final String[] args) {
        DOMTestCase.doMain(namednodemapinuseattributeerr.class, args);
   }
}


text:
import Form from '../form/form'
import { mergeData } from 'vue-functional-data-merge'

export default {
  functional: true,
  props: {
    id: {
      type: String,
      default: null
    }
  },
  render (h, { props, data, children }) {
    return h(Form, mergeData(data, { attrs: { id: props.id }, props: { inline: true } }), children)
  }
}


text:
// coding: utf-8
// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------
/*
 * WARNING: This file is generated automatically, do not edit!
 * Please modify the corresponding *.in file instead and rebuild this file.
 */
// ----------------------------------------------------------------------------

#ifndef XPCC_ATXMEGA__SPI_E_HPP
#define XPCC_ATXMEGA__SPI_E_HPP

#include <stdint.h>
#include <avr/io.h>
#include "spi.hpp"
#include <xpcc/driver/connectivity/spi/spi_master.hpp>
#include <xpcc/architecture/utils.hpp>

namespace xpcc
{
	namespace atxmega
	{
#if defined(SPIE) || defined(__DOXYGEN__)
		/**
		 * \brief		SPI Master for Port E
		 *
		 * This module only supports DMA read transfers in slave mode, however
		 * slave mode is not implemented here.
		 *
		 * \author		Niklas hauser
		 * \ingroup		atxmega_spi
		 */
		class SpiMasterE : public SpiMaster
		{
		public:
			static void
			initialize(spi::Prescaler prescaler=spi::PRESCALER_16,
					   spi::Mode mode=spi::MODE_0);

			inline static void
			setDataOrder(bool lsbFirst=true)
			{
				SPIE_CTRL = (SPIE_CTRL & ~SPI_DORD_bm) | (lsbFirst ? SPI_DORD_bm : 0);
			}

			static uint8_t
			write(uint8_t data);

			static bool
			setBuffer(uint16_t length,
					  uint8_t* transmit=0, uint8_t* receive=0,
					  BufferIncrease bufferIncrease=BUFFER_INCR_BOTH);

			static bool
			transfer(TransferOptions options=TRANSFER_SEND_BUFFER_SAVE_RECEIVE);

			static ALWAYS_INLINE bool
			transferSync(TransferOptions options=TRANSFER_SEND_BUFFER_SAVE_RECEIVE);

			static bool
			isFinished();

			inline static SPI_t&
			getModuleBase()
			{
				return SPIE;
			}
		};
#endif // SPIE

#if defined(USARTE0) || defined(__DOXYGEN__)
		/**
		 * \brief		UART0 in SPI master mode
		 *
		 * The USART pins are mapped like this MOSI=>TXO, MISO=>RXI, SCK=>XCK.
		 * Be aware that this module has no SS pin, so no slave mode is possible.
		 *
		 * This module supports DMA transfers between memory (SRAM) and DATA
		 * register by defining which DMA channel to use for write/read.
		 * (SPI0_TX_DMA_CHANNEL, SPI0_RX_DMA_CHANNEL)
		 * In typical use, the DMA channels gets configured once and then several
		 * transfers get triggered, without CPU interference.
		 *
		 * \author	Niklas Hauser
		 * \ingroup	atxmega_spi
		 */
		class UartSpiMasterE0 : public SpiMaster
		{
		public:
			/**
			 * Sets pins and calculates the bsel value of the UART module.
			 * The parameter has to be constant at compile time, so that
			 * the compiler can do the calculation, and not the uC.
			 * The DMA channel is configured with a Burst Length of one byte,
			 * reloading of source address after block transfer completion,
			 * incr./decr. of source address after each byte transfer,
			 * no reloading of fixed destination address (=UART DATA register).
			 *
			 * \warning The bitrate must be less than half F_CPU.
			 * \param	bitrate	SPI frequency in Hz
			 */
			static void
			initialize(uint32_t const bitrate=2000000);

			static uint8_t
			write(uint8_t data);

			static bool
			setBuffer(uint16_t length,
					  uint8_t* transmit=0, uint8_t* receive=0,
					  BufferIncrease bufferIncrease=BUFFER_INCR_BOTH);

			static bool
			transfer(TransferOptions options=TRANSFER_SEND_BUFFER_SAVE_RECEIVE);

			static bool
			transferSync(TransferOptions options=TRANSFER_SEND_BUFFER_SAVE_RECEIVE);

			static bool
			isFinished();

			inline static USART_t&
			getModuleBase()
			{
				return USARTE0;
			}

			inline static void
			setDataOrder(bool lsbFirst=true)
			{
				USARTE0_CTRLC = (USARTE0_CTRLC & ~USART_CHSIZE2_bm) | (lsbFirst ? USART_CHSIZE2_bm : 0);
			}

		private:
			static bool
			isBusy();
		};
#endif	// USARTE0

#if defined(USARTE1) || defined(__DOXYGEN__)
		/**
		 * \brief		UART1 in SPI master mode
		 *
		 * The USART pins are mapped like this MOSI=>TXO, MISO=>RXI, SCK=>XCK.
		 * Be aware that this module has no SS pin, so no slave mode is possible.
		 *
		 * This module supports DMA transfers between memory (SRAM) and DATA
		 * register by defining which DMA channel to use for write/read.
		 * (SPI1_TX_DMA_CHANNEL, SPI1_RX_DMA_CHANNEL)
		 * In typical use, the DMA channels gets configured once and then several
		 * transfers get triggered, without CPU interference.
		 *
		 * \author	Niklas Hauser
		 * \ingroup	atxmega_spi
		 */
		class UartSpiMasterE1 : public SpiMaster
		{
		public:
			/**
			 * Sets pins and calculates the bsel value of the UART module.
			 * The parameter has to be constant at compile time, so that
			 * the compiler can do the calculation, and not the uC.
			 * The DMA channel is configured with a Burst Length of one byte,
			 * reloading of source address after block transfer completion,
			 * incr./decr. of source address after each byte transfer,
			 * no reloading of fixed destination address (=UART DATA register).
			 *
			 * \warning The bitrate must be less than half F_CPU.
			 * \param	bitrate	SPI frequency in Hz
			 */
			static void
			initialize(uint32_t const bitrate=2000000);

			static uint8_t
			write(uint8_t data);

			static bool
			setBuffer(uint16_t length,
					  uint8_t* transmit=0, uint8_t* receive=0,
					  BufferIncrease bufferIncrease=BUFFER_INCR_BOTH);

			static bool
			transfer(TransferOptions options=TRANSFER_SEND_BUFFER_SAVE_RECEIVE);

			static bool
			transferSync(TransferOptions options=TRANSFER_SEND_BUFFER_SAVE_RECEIVE);

			static bool
			isFinished();

			inline static USART_t&
			getModuleBase()
			{
				return USARTE1;
			}

			inline static void
			setDataOrder(bool lsbFirst=true)
			{
				USARTE1_CTRLC = (USARTE1_CTRLC & ~USART_CHSIZE2_bm) | (lsbFirst ? USART_CHSIZE2_bm : 0);
			}

		private:
			static bool
			isBusy();
		};
#endif	// USARTE1
	}
}

#endif // XPCC_ATXMEGA__SPI_E_HPP


text:
package org.thingsboard.server.transport.lwm2m.bootstrap.secure;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.californium.elements.auth.RawPublicKeyIdentity;
import org.eclipse.californium.elements.util.CertPathUtil;
import org.eclipse.californium.scandium.dtls.AlertMessage;
import org.eclipse.californium.scandium.dtls.CertificateMessage;
import org.eclipse.californium.scandium.dtls.CertificateType;
import org.eclipse.californium.scandium.dtls.CertificateVerificationResult;
import org.eclipse.californium.scandium.dtls.ConnectionId;
import org.eclipse.californium.scandium.dtls.HandshakeException;
import org.eclipse.californium.scandium.dtls.HandshakeResultHandler;
import org.eclipse.californium.scandium.dtls.x509.NewAdvancedCertificateVerifier;
import org.eclipse.californium.scandium.dtls.x509.StaticNewAdvancedCertificateVerifier;
import org.eclipse.californium.scandium.util.ServerNames;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.msg.EncryptionUtil;
import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
import org.thingsboard.server.common.transport.util.SslUtil;
import org.thingsboard.server.queue.util.TbLwM2mBootstrapTransportComponent;
import org.thingsboard.server.transport.lwm2m.bootstrap.store.LwM2MBootstrapSecurityStore;
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException;

import javax.annotation.PostConstruct;
import javax.security.auth.x500.X500Principal;
import java.net.InetSocketAddress;
import java.security.PublicKey;
import java.security.cert.CertPath;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.List;

@Slf4j
@Component
@TbLwM2mBootstrapTransportComponent
@RequiredArgsConstructor
public class TbLwM2MDtlsBootstrapCertificateVerifier implements NewAdvancedCertificateVerifier {

    private final LwM2MTransportServerConfig config;
    private final LwM2MBootstrapSecurityStore bsSecurityStore;

    private StaticNewAdvancedCertificateVerifier staticCertificateVerifier;

    @Value("${transport.lwm2m.server.security.skip_validity_check_for_client_cert:false}")
    private boolean skipValidityCheckForClientCert;

    @Override
    public List<CertificateType> getSupportedCertificateTypes() {
        return Arrays.asList(CertificateType.X_509, CertificateType.RAW_PUBLIC_KEY);
    }

    @SuppressWarnings("deprecation")
    @PostConstruct
    public void init() {
        try {
            /* by default trust all */
            if (config.getTrustSslCredentials() != null) {
                X509Certificate[] trustedCertificates = config.getTrustSslCredentials().getTrustedCertificates();
                staticCertificateVerifier = new StaticNewAdvancedCertificateVerifier(trustedCertificates, new RawPublicKeyIdentity[0], null);
            }
        } catch (Exception e) {
            log.warn("ailed to initialize the LwM2M certificate verifier", e);
        }
    }

    @Override
    public CertificateVerificationResult verifyCertificate(ConnectionId cid, ServerNames serverName, InetSocketAddress remotePeer,
                                                           boolean clientUsage, boolean verifySubject, boolean truncateCertificatePath,
                                                           CertificateMessage message) {
        CertPath certChain = message.getCertificateChain();
        if (certChain == null) {
            //We trust all RPK on this layer, and use TbLwM2MAuthorizer
            PublicKey publicKey = message.getPublicKey();
            return new CertificateVerificationResult(cid, publicKey, null);
        } else {
            try {
                boolean x509CredentialsFound = false;
                X509Certificate[] chain = certChain.getCertificates().toArray(new X509Certificate[0]);
                for (X509Certificate cert : chain) {
                    try {
                        if (!skipValidityCheckForClientCert) {
                            cert.checkValidity();
                        }
                        TbLwM2MSecurityInfo securityInfo = null;
                        // verify if trust
                        if (staticCertificateVerifier != null) {
                            HandshakeException exception = staticCertificateVerifier.verifyCertificate(cid, serverName, remotePeer, clientUsage, verifySubject, truncateCertificatePath, message).getException();
                            if (exception == null) {
                                String endpoint = config.getTrustSslCredentials().getValueFromSubjectNameByKey(cert.getSubjectX500Principal().getName(), "CN");
                                if (StringUtils.isNotEmpty(endpoint)) {
                                    securityInfo = bsSecurityStore.getX509ByEndpoint(endpoint);
                                }
                            } else {
                                log.trace("Certificate validation failed.", exception);
                            }
                        }
                        // if not trust or cert trust securityInfo == null
                        if (securityInfo == null || securityInfo.getMsg() == null) {
                            String strCert = SslUtil.getCertificateString(cert);
                            String sha3Hash = EncryptionUtil.getSha3Hash(strCert);
                            try {
                                securityInfo = bsSecurityStore.getX509ByEndpoint(sha3Hash);
                            } catch (LwM2MAuthException e) {
                                log.trace("Failed to find security info: [{}]", sha3Hash, e);
                            }
                        }
                        ValidateDeviceCredentialsResponse msg = securityInfo != null ? securityInfo.getMsg() : null;
                        if (msg != null && StringUtils.isNotEmpty(msg.getCredentials())) {
                            x509CredentialsFound = true;
                            break;
                        }
                    } catch (CertificateEncodingException |
                            CertificateExpiredException |
                            CertificateNotYetValidException e) {
                        log.trace("Failed to find security info: [{}]", cert.getSubjectX500Principal().getName(), e);
                    }
                }
                if (!x509CredentialsFound) {
                    AlertMessage alert = new AlertMessage(AlertMessage.AlertLevel.FATAL, AlertMessage.AlertDescription.INTERNAL_ERROR);
                    throw new HandshakeException("x509 verification not enabled!", alert);
                }
                return new CertificateVerificationResult(cid, certChain, null);
            } catch (HandshakeException e) {
                log.trace("Certificate validation failed!", e);
                return new CertificateVerificationResult(cid, e, null);
            }
        }
    }

    @Override
    public List<X500Principal> getAcceptedIssuers() {
        return CertPathUtil.toSubjects(null);
    }

    @Override
    public void setResultHandler(HandshakeResultHandler resultHandler) {

    }
}


text:
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Test.ModuleCore;

namespace CoreXml.Test.XLinq
{
    public partial class FunctionalTests : TestModule
    {

        public partial class XNodeReaderTests : XLinqTestCase
        {
            public partial class TCDispose : BridgeHelpers
            {
                //[Variation("Test Integrity of all values after Dispose")]
                public void Variation1()
                {
                    XmlReader DataReader = GetReader();
                    ((IDisposable)DataReader).Dispose();

                    TestLog.Compare(DataReader.Name, String.Empty, "Name");
                    TestLog.Compare(DataReader.NodeType, XmlNodeType.None, "NodeType");
                    TestLog.Compare(DataReader.ReadState, ReadState.Closed, "ReadState");
                    TestLog.Compare(DataReader.AttributeCount, 0, "Attrib Count");
                    TestLog.Compare(DataReader.XmlLang, String.Empty, "XML Lang");
                    TestLog.Compare(DataReader.XmlSpace, XmlSpace.None, "Space");
                    TestLog.Compare(DataReader.BaseURI, String.Empty, "BaseUri");
                    TestLog.Compare(DataReader.Depth, 0, "Depth");
                    TestLog.Compare(DataReader.EOF, false, "EOF");
                    TestLog.Compare(DataReader.HasAttributes, false, "HasAttr");
                    TestLog.Compare(DataReader.HasValue, false, "HasValue");
                    TestLog.Compare(DataReader.IsDefault, false, "IsDefault");
                    TestLog.Compare(DataReader.LocalName, String.Empty, "LocalName");
                    try
                    {
                        TestLog.Compare(((IXmlLineInfo)DataReader).LineNumber, 0, "Line number");
                    }
                    catch (InvalidCastException) { }
                    try
                    {
                        TestLog.Compare(((IXmlLineInfo)DataReader).LinePosition, 0, "Line Position");
                    }
                    catch (InvalidCastException) { }
                    TestLog.Compare(DataReader.IsEmptyElement, false, "IsEmptyElement");
                    TestLog.Compare(DataReader.Read(), false, "Read");
                    TestLog.Compare(DataReader.ReadAttributeValue(), false, "ReadAV");
                    TestLog.Compare(DataReader.ReadInnerXml(), string.Empty, "ReadIX");
                    TestLog.Compare(DataReader.ReadOuterXml(), string.Empty, "ReadOX");
                }

                //[Variation("Call Dispose Multiple(3) Times")]
                public void Variation2()
                {
                    foreach (XNode n in GetXNodeR())
                    {
                        XmlReader r = n.CreateReader();
                        ((IDisposable)r).Dispose();
                        ((IDisposable)r).Dispose();
                        ((IDisposable)r).Dispose();
                    }
                }

                //GetXNode List
                public List<XNode> GetXNodeR()
                {
                    List<XNode> xNode = new List<XNode>();

                    xNode.Add(new XDocument(new XDocumentType("root", "", "", "<!ELEMENT root ANY>"), new XElement("root")));
                    xNode.Add(new XElement("elem1"));
                    xNode.Add(new XText("text1"));
                    xNode.Add(new XComment("comment1"));
                    xNode.Add(new XProcessingInstruction("pi1", "pi1pi1pi1pi1pi1"));
                    xNode.Add(new XCData("cdata cdata"));
                    xNode.Add(new XDocumentType("dtd1", "dtd1dtd1dtd1", "dtd1dtd1", "dtd1dtd1dtd1dtd1"));
                    return xNode;
                }
            }
        }
    }
}


text:
package peersim.util;

import java.io.*;

/**
* Generates a series of filenames for classes that have to save e.g.
* snapshots regularly.
*/
public class FileNameGenerator {

/**
* The number of filenames already returned.
*/
private long counter = 0;

/** The prefix of the filename */
public final String prefix;

/** The extension of the filename */
public final String ext;

// ==================== initialization ==============================
// ==================================================================

/**
* @param prefix all returned names will be prefixed by this
* @param ext will be appended to all returned names
*/
public FileNameGenerator(String prefix, String ext) {

	this.prefix=prefix;
	this.ext=ext;
}

// ===================== methods ====================================
// ==================================================================

/**
* Generates a name based on a counter.
* The format of the name returned is {@link #prefix} followed by
* an 8 digit zero padded number, followed by {@link #ext}.
* The first number used is zero.
* @return the next filename after increasing the counter
*/
public String nextCounterName() {

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	(new PrintStream(baos)).printf("%08d",counter);
	counter++;
	return prefix+baos.toString()+ext;
}

// ------------------------------------------------------------------

/*
public static void main(String args[]) {

	FileNameGenerator fng = new FileNameGenerator(args[0],args[1]);
	for(int i=0; i<100; ++i) System.err.println(fng.nextCounterName());
}
*/
}


text:
package com.cloudera.testio;

import junit.framework.TestCase;

import com.cloudera.util.Benchmark;

/**
 * There are three formats for handling blobs of data. Which is the most
 * efficient, which are the most convenient and which are the cheapest to
 * translate to and from?
 *
 */

// String --------> 1.3s 1.4 1.3 --------> 7.7Mops/s
// StringBuffer --> 1.2s 1.2 1.2 --------> 8.3Mops/s
// StringBuilder -> .75s 0.77 .78 ------> 13.0Mops/s
// StringFormat --> 13.9s 14.3 15.7 -----> 0.7Mops/s

public class PerfStringAppends extends TestCase {
  int times = 10000000;

  String base = "this is a test";

  public void testStringAppend() {
    Benchmark b = new Benchmark("String Append");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      @SuppressWarnings("unused")
      String temp = base + i;
    }
    b.mark("after " + times);
    b.done();
  }

  public void testStringBufferAppend() {
    StringBuffer buf = new StringBuffer(base);
    Benchmark b = new Benchmark("StringBuffer Append");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      buf.append(i);
    }
    b.mark("after " + times);
    b.done();
  }

  public void testStringBuilderAppend() {
    StringBuilder buf = new StringBuilder(base);
    Benchmark b = new Benchmark("StringBuffer Append");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      buf.append(i);
    }
    b.mark("after " + times);
    b.done();
  }

  public void testStringFormat() {
    String format = "%s%d";
    Benchmark b = new Benchmark("StringFormatAppend");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      String.format(format, base, i);
    }
    b.mark("after " + times);
    b.done();

  }

  public void testStringAppend2() {
    Benchmark b = new Benchmark("String Append");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      @SuppressWarnings("unused")
      String temp = base + i;
    }
    b.mark("after " + times);
    b.done();
  }

  public void testStringBufferAppend2() {
    StringBuffer buf = new StringBuffer(base);
    Benchmark b = new Benchmark("StringBuffer Append");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      buf.append(i);
    }
    b.mark("after " + times);
    b.done();
  }

  public void testStringBuilderAppend2() {
    StringBuilder buf = new StringBuilder(base);
    Benchmark b = new Benchmark("StringBuffer Append");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      buf.append(i);
    }
    b.mark("after " + times);
    b.done();
  }

  public void testStringFormat2() {
    String format = "%s%d";
    Benchmark b = new Benchmark("StringFormatAppend");

    b.mark("begin");
    for (int i = 0; i < times; i++) {
      String.format(format, base, i);
    }
    b.mark("after " + times);
    b.done();

  }

}


text:
The plugin provides instant feedback whether written HTML code conforms to following defined rules or not. The user can enable and disable the continuous issue checking and check the whole page on command. These features can be used via key combinations or via the ATOM menu Packages / Web Accessibility Checker. The defined rules have been selected because they can easily be checked without knowlegde of the complete website, JS files and CSS files. **The plugin has still some small bugs, but it is stable and the core functionality is working. (in all tested conditions till now)**

![alt text](https://raw.githubusercontent.com/web-weber/web-accessibility-checker/master/web-accessibility-checker.gif "Example image of instance feedback")

## Rules
### Img alternative
**WCAG 2.0 chapter:** 1.1.1
**Rule:** ```Each <img> tag should have an alt attribute.```

### Label
**WCAG 2.0 chapter:** 3.3.2
**Rule:** ```Each <input> tag should have a <label> tag, where the for attribute match the id attribute of the <input> tag OR the <label> tag covers the <input> tag and the description.```

### Page title
**WCAG 2.0 chapter:** 2.4.2
**Rule:** ```A <head> section should include a <title> element.```

### Language
**WCAG 2.0 chapter:** 3.1.1
**Rule:** ```The lang attribute should be defined in the <html> tag.```

### Link
**WCAG 2.0 chapter:** 2.4.9
**Rule:** ```<a> tags should only include a title attribute if it is not possible to make the link destination clear with the link text alone.```

## More information
The algorithms are mainly based on regExp. The testing of those was done through code samples with the consequences that the amount and diversity of those are an important factor for the quality of the results. Till now the algorithms work quite good and fast enough to provide a instant feedback feeling (about 50ms execution time). To ensure that the typing experience will not get influenced, the package will check the page 300ms after the user stopped typing.
In case of interest, I could invest more time to fix the known issues or if you want to further develop the plugin, feel free to contact me.

## Known bugs
**Tooltips:** If the user scrolls the highlighted code section and therefore also the element which displays onMouseOver a tooltip with extra information, out of the visible area of the current editor, the tooltip is not working anymore.


text:
using System.Globalization;
using System.Runtime.InteropServices;
using Xunit;

namespace System.Numerics.Tests
{
    public class Vector3Tests
    {
        [Fact]
        public void Vector3MarshalSizeTest()
        {
            Assert.Equal(12, Marshal.SizeOf<Vector3>());
            Assert.Equal(12, Marshal.SizeOf<Vector3>(new Vector3()));
        }

        [Fact]
        public void Vector3CopyToTest()
        {
            Vector3 v1 = new Vector3(2.0f, 3.0f, 3.3f);

            float[] a = new float[4];
            float[] b = new float[3];

            Assert.Throws<NullReferenceException>(() => v1.CopyTo(null, 0));
            Assert.Throws<ArgumentOutOfRangeException>(() => v1.CopyTo(a, -1));
            Assert.Throws<ArgumentOutOfRangeException>(() => v1.CopyTo(a, a.Length));
            Assert.Throws<ArgumentException>(() => v1.CopyTo(a, a.Length - 2));

            v1.CopyTo(a, 1);
            v1.CopyTo(b);
            Assert.Equal(0.0f, a[0]);
            Assert.Equal(2.0f, a[1]);
            Assert.Equal(3.0f, a[2]);
            Assert.Equal(3.3f, a[3]);
            Assert.Equal(2.0f, b[0]);
            Assert.Equal(3.0f, b[1]);
            Assert.Equal(3.3f, b[2]);
        }

        [Fact]
        public void Vector3GetHashCodeTest()
        {
            Vector3 v1 = new Vector3(2.0f, 3.0f, 3.3f);
            Vector3 v2 = new Vector3(2.0f, 3.0f, 3.3f);
            Vector3 v3 = new Vector3(2.0f, 3.0f, 3.3f);
            Vector3 v5 = new Vector3(3.0f, 2.0f, 3.3f);
            Assert.Equal(v1.GetHashCode(), v1.GetHashCode());
            Assert.Equal(v1.GetHashCode(), v2.GetHashCode());
            Assert.NotEqual(v1.GetHashCode(), v5.GetHashCode());
            Assert.Equal(v1.GetHashCode(), v3.GetHashCode());
            Vector3 v4 = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 v6 = new Vector3(1.0f, 0.0f, 0.0f);
            Vector3 v7 = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 v8 = new Vector3(1.0f, 1.0f, 1.0f);
            Vector3 v9 = new Vector3(1.0f, 1.0f, 0.0f);
            Assert.NotEqual(v4.GetHashCode(), v6.GetHashCode());
            Assert.NotEqual(v4.GetHashCode(), v7.GetHashCode());
            Assert.NotEqual(v4.GetHashCode(), v8.GetHashCode());
            Assert.NotEqual(v7.GetHashCode(), v6.GetHashCode());
            Assert.NotEqual(v8.GetHashCode(), v6.GetHashCode());
            Assert.NotEqual(v8.GetHashCode(), v9.GetHashCode());
            Assert.NotEqual(v7.GetHashCode(), v9.GetHashCode());
        }

        [Fact]
        public void Vector3ToStringTest()
        {
            string separator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
            CultureInfo enUsCultureInfo = new CultureInfo("en-US");

            Vector3 v1 = new Vector3(2.0f, 3.0f, 3.3f);
            string v1str = v1.ToString();
            string expectedv1 = string.Format(CultureInfo.CurrentCulture
                , "<{1:G}{0} {2:G}{0} {3:G}>"
                , separator, 2, 3, 3.3);
            Assert.Equal(expectedv1, v1str);

            string v1strformatted = v1.ToString("c", CultureInfo.CurrentCulture);
            string expectedv1formatted = string.Format(CultureInfo.CurrentCulture
                , "<{1:c}{0} {2:c}{0} {3:c}>"
                , separator, 2, 3, 3.3);
            Assert.Equal(expectedv1formatted, v1strformatted);

            string v2strformatted = v1.ToString("c", enUsCultureInfo);
            string expectedv2formatted = string.Format(enUsCultureInfo
                , "<{1:c}{0} {2:c}{0} {3:c}>"
                , enUsCultureInfo.NumberFormat.NumberGroupSeparator, 2, 3, 3.3);
            Assert.Equal(expectedv2formatted, v2strformatted);

            string v3strformatted = v1.ToString("c");
            string expectedv3formatted = string.Format(CultureInfo.CurrentCulture
                , "<{1:c}{0} {2:c}{0} {3:c}>"
                , separator, 2, 3, 3.3);
            Assert.Equal(expectedv3formatted, v3strformatted);
        }

        // A test for Cross (Vector3f, Vector3f)
        [Fact]
        public void Vector3CrossTest()
        {
            Vector3 a = new Vector3(1.0f, 0.0f, 0.0f);
            Vector3 b = new Vector3(0.0f, 1.0f, 0.0f);

            Vector3 expected = new Vector3(0.0f, 0.0f, 1.0f);
            Vector3 actual;

            actual = Vector3.Cross(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Cross did not return the expected value.");
        }

        // A test for Cross (Vector3f, Vector3f)
        // Cross test of the same vector
        [Fact]
        public void Vector3CrossTest1()
        {
            Vector3 a = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 b = new Vector3(0.0f, 1.0f, 0.0f);

            Vector3 expected = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 actual = Vector3.Cross(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Cross did not return the expected value.");
        }

        // A test for Distance (Vector3f, Vector3f)
        [Fact]
        public void Vector3DistanceTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float expected = (float)System.Math.Sqrt(27);
            float actual;

            actual = Vector3.Distance(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Distance did not return the expected value.");
        }

        // A test for Distance (Vector3f, Vector3f)
        // Distance from the same point
        [Fact]
        public void Vector3DistanceTest1()
        {
            Vector3 a = new Vector3(1.051f, 2.05f, 3.478f);
            Vector3 b = new Vector3(new Vector2(1.051f, 0.0f), 1);
            b.Y = 2.05f;
            b.Z = 3.478f;

            float actual = Vector3.Distance(a, b);
            Assert.Equal(0.0f, actual);
        }

        // A test for DistanceSquared (Vector3f, Vector3f)
        [Fact]
        public void Vector3DistanceSquaredTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float expected = 27.0f;
            float actual;

            actual = Vector3.DistanceSquared(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.DistanceSquared did not return the expected value.");
        }

        // A test for Dot (Vector3f, Vector3f)
        [Fact]
        public void Vector3DotTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float expected = 32.0f;
            float actual;

            actual = Vector3.Dot(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Dot did not return the expected value.");
        }

        // A test for Dot (Vector3f, Vector3f)
        // Dot test for perpendicular vector
        [Fact]
        public void Vector3DotTest1()
        {
            Vector3 a = new Vector3(1.55f, 1.55f, 1);
            Vector3 b = new Vector3(2.5f, 3, 1.5f);
            Vector3 c = Vector3.Cross(a, b);

            float expected = 0.0f;
            float actual1 = Vector3.Dot(a, c);
            float actual2 = Vector3.Dot(b, c);
            Assert.True(MathHelper.Equal(expected, actual1), "Vector3f.Dot did not return the expected value.");
            Assert.True(MathHelper.Equal(expected, actual2), "Vector3f.Dot did not return the expected value.");
        }

        // A test for Length ()
        [Fact]
        public void Vector3LengthTest()
        {
            Vector2 a = new Vector2(1.0f, 2.0f);

            float z = 3.0f;

            Vector3 target = new Vector3(a, z);

            float expected = (float)System.Math.Sqrt(14.0f);
            float actual;

            actual = target.Length();
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Length did not return the expected value.");
        }

        // A test for Length ()
        // Length test where length is zero
        [Fact]
        public void Vector3LengthTest1()
        {
            Vector3 target = new Vector3();

            float expected = 0.0f;
            float actual = target.Length();
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Length did not return the expected value.");
        }

        // A test for LengthSquared ()
        [Fact]
        public void Vector3LengthSquaredTest()
        {
            Vector2 a = new Vector2(1.0f, 2.0f);

            float z = 3.0f;

            Vector3 target = new Vector3(a, z);

            float expected = 14.0f;
            float actual;

            actual = target.LengthSquared();
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.LengthSquared did not return the expected value.");
        }

        // A test for Min (Vector3f, Vector3f)
        [Fact]
        public void Vector3MinTest()
        {
            Vector3 a = new Vector3(-1.0f, 4.0f, -3.0f);
            Vector3 b = new Vector3(2.0f, 1.0f, -1.0f);

            Vector3 expected = new Vector3(-1.0f, 1.0f, -3.0f);
            Vector3 actual;
            actual = Vector3.Min(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Min did not return the expected value.");
        }

        // A test for Max (Vector3f, Vector3f)
        [Fact]
        public void Vector3MaxTest()
        {
            Vector3 a = new Vector3(-1.0f, 4.0f, -3.0f);
            Vector3 b = new Vector3(2.0f, 1.0f, -1.0f);

            Vector3 expected = new Vector3(2.0f, 4.0f, -1.0f);
            Vector3 actual;
            actual = Vector3.Max(a, b);
            Assert.True(MathHelper.Equal(expected, actual), "vector3.Max did not return the expected value.");
        }

        [Fact]
        public void Vector3MinMaxCodeCoverageTest()
        {
            Vector3 min = Vector3.Zero;
            Vector3 max = Vector3.One;
            Vector3 actual;

            // Min.
            actual = Vector3.Min(min, max);
            Assert.Equal(actual, min);

            actual = Vector3.Min(max, min);
            Assert.Equal(actual, min);

            // Max.
            actual = Vector3.Max(min, max);
            Assert.Equal(actual, max);

            actual = Vector3.Max(max, min);
            Assert.Equal(actual, max);
        }

        // A test for Lerp (Vector3f, Vector3f, float)
        [Fact]
        public void Vector3LerpTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float t = 0.5f;

            Vector3 expected = new Vector3(2.5f, 3.5f, 4.5f);
            Vector3 actual;

            actual = Vector3.Lerp(a, b, t);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }

        // A test for Lerp (Vector3f, Vector3f, float)
        // Lerp test with factor zero
        [Fact]
        public void Vector3LerpTest1()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float t = 0.0f;
            Vector3 expected = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 actual = Vector3.Lerp(a, b, t);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }

        // A test for Lerp (Vector3f, Vector3f, float)
        // Lerp test with factor one
        [Fact]
        public void Vector3LerpTest2()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float t = 1.0f;
            Vector3 expected = new Vector3(4.0f, 5.0f, 6.0f);
            Vector3 actual = Vector3.Lerp(a, b, t);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }

        // A test for Lerp (Vector3f, Vector3f, float)
        // Lerp test with factor > 1
        [Fact]
        public void Vector3LerpTest3()
        {
            Vector3 a = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float t = 2.0f;
            Vector3 expected = new Vector3(8.0f, 10.0f, 12.0f);
            Vector3 actual = Vector3.Lerp(a, b, t);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }

        // A test for Lerp (Vector3f, Vector3f, float)
        // Lerp test with factor < 0
        [Fact]
        public void Vector3LerpTest4()
        {
            Vector3 a = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            float t = -2.0f;
            Vector3 expected = new Vector3(-8.0f, -10.0f, -12.0f);
            Vector3 actual = Vector3.Lerp(a, b, t);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }

        // A test for Lerp (Vector3f, Vector3f, float)
        // Lerp test from the same point
        [Fact]
        public void Vector3LerpTest5()
        {
            Vector3 a = new Vector3(1.68f, 2.34f, 5.43f);
            Vector3 b = a;

            float t = 0.18f;
            Vector3 expected = new Vector3(1.68f, 2.34f, 5.43f);
            Vector3 actual = Vector3.Lerp(a, b, t);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Lerp did not return the expected value.");
        }

        // A test for Reflect (Vector3f, Vector3f)
        [Fact]
        public void Vector3ReflectTest()
        {
            Vector3 a = Vector3.Normalize(new Vector3(1.0f, 1.0f, 1.0f));

            // Reflect on XZ plane.
            Vector3 n = new Vector3(0.0f, 1.0f, 0.0f);
            Vector3 expected = new Vector3(a.X, -a.Y, a.Z);
            Vector3 actual = Vector3.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Reflect did not return the expected value.");

            // Reflect on XY plane.
            n = new Vector3(0.0f, 0.0f, 1.0f);
            expected = new Vector3(a.X, a.Y, -a.Z);
            actual = Vector3.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Reflect did not return the expected value.");

            // Reflect on YZ plane.
            n = new Vector3(1.0f, 0.0f, 0.0f);
            expected = new Vector3(-a.X, a.Y, a.Z);
            actual = Vector3.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Reflect did not return the expected value.");
        }

        // A test for Reflect (Vector3f, Vector3f)
        // Reflection when normal and source are the same
        [Fact]
        public void Vector3ReflectTest1()
        {
            Vector3 n = new Vector3(0.45f, 1.28f, 0.86f);
            n = Vector3.Normalize(n);
            Vector3 a = n;

            Vector3 expected = -n;
            Vector3 actual = Vector3.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Reflect did not return the expected value.");
        }

        // A test for Reflect (Vector3f, Vector3f)
        // Reflection when normal and source are negation
        [Fact]
        public void Vector3ReflectTest2()
        {
            Vector3 n = new Vector3(0.45f, 1.28f, 0.86f);
            n = Vector3.Normalize(n);
            Vector3 a = -n;

            Vector3 expected = n;
            Vector3 actual = Vector3.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Reflect did not return the expected value.");
        }

        // A test for Reflect (Vector3f, Vector3f)
        // Reflection when normal and source are perpendicular (a dot n = 0)
        [Fact]
        public void Vector3ReflectTest3()
        {
            Vector3 n = new Vector3(0.45f, 1.28f, 0.86f);
            Vector3 temp = new Vector3(1.28f, 0.45f, 0.01f);
            // find a perpendicular vector of n
            Vector3 a = Vector3.Cross(temp, n);

            Vector3 expected = a;
            Vector3 actual = Vector3.Reflect(a, n);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Reflect did not return the expected value.");
        }

        // A test for Transform(Vector3f, Matrix4x4)
        [Fact]
        public void Vector3TransformTest()
        {
            Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);
            Matrix4x4 m =
                Matrix4x4.CreateRotationX(MathHelper.ToRadians(30.0f)) *
                Matrix4x4.CreateRotationY(MathHelper.ToRadians(30.0f)) *
                Matrix4x4.CreateRotationZ(MathHelper.ToRadians(30.0f));
            m.M41 = 10.0f;
            m.M42 = 20.0f;
            m.M43 = 30.0f;

            Vector3 expected = new Vector3(12.191987f, 21.533493f, 32.616024f);
            Vector3 actual;

            actual = Vector3.Transform(v, m);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value.");
        }

        // A test for Clamp (Vector3f, Vector3f, Vector3f)
        [Fact]
        public void Vector3ClampTest()
        {
            Vector3 a = new Vector3(0.5f, 0.3f, 0.33f);
            Vector3 min = new Vector3(0.0f, 0.1f, 0.13f);
            Vector3 max = new Vector3(1.0f, 1.1f, 1.13f);

            // Normal case.
            // Case N1: specified value is in the range.
            Vector3 expected = new Vector3(0.5f, 0.3f, 0.33f);
            Vector3 actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Normal case.
            // Case N2: specified value is bigger than max value.
            a = new Vector3(2.0f, 3.0f, 4.0f);
            expected = max;
            actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Case N3: specified value is smaller than max value.
            a = new Vector3(-2.0f, -3.0f, -4.0f);
            expected = min;
            actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Case N4: combination case.
            a = new Vector3(-2.0f, 0.5f, 4.0f);
            expected = new Vector3(min.X, a.Y, max.Z);
            actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // User specified min value is bigger than max value.
            max = new Vector3(0.0f, 0.1f, 0.13f);
            min = new Vector3(1.0f, 1.1f, 1.13f);

            // Case W1: specified value is in the range.
            a = new Vector3(0.5f, 0.3f, 0.33f);
            expected = min;
            actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Normal case.
            // Case W2: specified value is bigger than max and min value.
            a = new Vector3(2.0f, 3.0f, 4.0f);
            expected = min;
            actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");

            // Case W3: specified value is smaller than min and max value.
            a = new Vector3(-2.0f, -3.0f, -4.0f);
            expected = min;
            actual = Vector3.Clamp(a, min, max);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value.");
        }

        // A test for TransformNormal (Vector3f, Matrix4x4)
        [Fact]
        public void Vector3TransformNormalTest()
        {
            Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);
            Matrix4x4 m =
                Matrix4x4.CreateRotationX(MathHelper.ToRadians(30.0f)) *
                Matrix4x4.CreateRotationY(MathHelper.ToRadians(30.0f)) *
                Matrix4x4.CreateRotationZ(MathHelper.ToRadians(30.0f));
            m.M41 = 10.0f;
            m.M42 = 20.0f;
            m.M43 = 30.0f;

            Vector3 expected = new Vector3(2.19198728f, 1.53349364f, 2.61602545f);
            Vector3 actual;

            actual = Vector3.TransformNormal(v, m);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.TransformNormal did not return the expected value.");
        }

        // A test for Transform (Vector3f, Quaternion)
        [Fact]
        public void Vector3TransformByQuaternionTest()
        {
            Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);

            Matrix4x4 m =
                Matrix4x4.CreateRotationX(MathHelper.ToRadians(30.0f)) *
                Matrix4x4.CreateRotationY(MathHelper.ToRadians(30.0f)) *
                Matrix4x4.CreateRotationZ(MathHelper.ToRadians(30.0f));
            Quaternion q = Quaternion.CreateFromRotationMatrix(m);

            Vector3 expected = Vector3.Transform(v, m);
            Vector3 actual = Vector3.Transform(v, q);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value.");
        }

        // A test for Transform (Vector3f, Quaternion)
        // Transform vector3 with zero quaternion
        [Fact]
        public void Vector3TransformByQuaternionTest1()
        {
            Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);
            Quaternion q = new Quaternion();
            Vector3 expected = v;

            Vector3 actual = Vector3.Transform(v, q);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value.");
        }

        // A test for Transform (Vector3f, Quaternion)
        // Transform vector3 with identity quaternion
        [Fact]
        public void Vector3TransformByQuaternionTest2()
        {
            Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);
            Quaternion q = Quaternion.Identity;
            Vector3 expected = v;

            Vector3 actual = Vector3.Transform(v, q);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value.");
        }

        // A test for Normalize (Vector3f)
        [Fact]
        public void Vector3NormalizeTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(
                0.26726124191242438468455348087975f,
                0.53452248382484876936910696175951f,
                0.80178372573727315405366044263926f);
            Vector3 actual;

            actual = Vector3.Normalize(a);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Normalize did not return the expected value.");
        }

        // A test for Normalize (Vector3f)
        // Normalize vector of length one
        [Fact]
        public void Vector3NormalizeTest1()
        {
            Vector3 a = new Vector3(1.0f, 0.0f, 0.0f);

            Vector3 expected = new Vector3(1.0f, 0.0f, 0.0f);
            Vector3 actual = Vector3.Normalize(a);
            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Normalize did not return the expected value.");
        }

        // A test for Normalize (Vector3f)
        // Normalize vector of length zero
        [Fact]
        public void Vector3NormalizeTest2()
        {
            Vector3 a = new Vector3(0.0f, 0.0f, 0.0f);

            Vector3 expected = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 actual = Vector3.Normalize(a);
            Assert.True(float.IsNaN(actual.X) && float.IsNaN(actual.Y) && float.IsNaN(actual.Z), "Vector3f.Normalize did not return the expected value.");
        }

        // A test for operator - (Vector3f)
        [Fact]
        public void Vector3UnaryNegationTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(-1.0f, -2.0f, -3.0f);
            Vector3 actual;

            actual = -a;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator - did not return the expected value.");
        }

        [Fact]
        public void Vector3UnaryNegationTest1()
        {
            Vector3 a = -new Vector3(Single.NaN, Single.PositiveInfinity, Single.NegativeInfinity);
            Vector3 b = -new Vector3(0.0f, 0.0f, 0.0f);
            Assert.Equal(Single.NaN, a.X);
            Assert.Equal(Single.NegativeInfinity, a.Y);
            Assert.Equal(Single.PositiveInfinity, a.Z);
            Assert.Equal(0.0f, b.X);
            Assert.Equal(0.0f, b.Y);
            Assert.Equal(0.0f, b.Z);
        }

        // A test for operator - (Vector3f, Vector3f)
        [Fact]
        public void Vector3SubtractionTest()
        {
            Vector3 a = new Vector3(4.0f, 2.0f, 3.0f);

            Vector3 b = new Vector3(1.0f, 5.0f, 7.0f);

            Vector3 expected = new Vector3(3.0f, -3.0f, -4.0f);
            Vector3 actual;

            actual = a - b;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator - did not return the expected value.");
        }

        // A test for operator * (Vector3f, float)
        [Fact]
        public void Vector3MultiplyOperatorTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            float factor = 2.0f;

            Vector3 expected = new Vector3(2.0f, 4.0f, 6.0f);
            Vector3 actual;

            actual = a * factor;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator * did not return the expected value.");
        }

        // A test for operator * (float, Vector3f)
        [Fact]
        public void Vector3MultiplyOperatorTest2()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            const float factor = 2.0f;

            Vector3 expected = new Vector3(2.0f, 4.0f, 6.0f);
            Vector3 actual;

            actual = factor * a;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator * did not return the expected value.");
        }

        // A test for operator * (Vector3f, Vector3f)
        [Fact]
        public void Vector3MultiplyOperatorTest3()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            Vector3 expected = new Vector3(4.0f, 10.0f, 18.0f);
            Vector3 actual;

            actual = a * b;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator * did not return the expected value.");
        }

        // A test for operator / (Vector3f, float)
        [Fact]
        public void Vector3DivisionTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            float div = 2.0f;

            Vector3 expected = new Vector3(0.5f, 1.0f, 1.5f);
            Vector3 actual;

            actual = a / div;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator / did not return the expected value.");
        }

        // A test for operator / (Vector3f, Vector3f)
        [Fact]
        public void Vector3DivisionTest1()
        {
            Vector3 a = new Vector3(4.0f, 2.0f, 3.0f);

            Vector3 b = new Vector3(1.0f, 5.0f, 6.0f);

            Vector3 expected = new Vector3(4.0f, 0.4f, 0.5f);
            Vector3 actual;

            actual = a / b;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator / did not return the expected value.");
        }

        // A test for operator / (Vector3f, Vector3f)
        // Divide by zero
        [Fact]
        public void Vector3DivisionTest2()
        {
            Vector3 a = new Vector3(-2.0f, 3.0f, float.MaxValue);

            float div = 0.0f;

            Vector3 actual = a / div;

            Assert.True(float.IsNegativeInfinity(actual.X), "Vector3f.operator / did not return the expected value.");
            Assert.True(float.IsPositiveInfinity(actual.Y), "Vector3f.operator / did not return the expected value.");
            Assert.True(float.IsPositiveInfinity(actual.Z), "Vector3f.operator / did not return the expected value.");
        }

        // A test for operator / (Vector3f, Vector3f)
        // Divide by zero
        [Fact]
        public void Vector3DivisionTest3()
        {
            Vector3 a = new Vector3(0.047f, -3.0f, float.NegativeInfinity);
            Vector3 b = new Vector3();

            Vector3 actual = a / b;

            Assert.True(float.IsPositiveInfinity(actual.X), "Vector3f.operator / did not return the expected value.");
            Assert.True(float.IsNegativeInfinity(actual.Y), "Vector3f.operator / did not return the expected value.");
            Assert.True(float.IsNegativeInfinity(actual.Z), "Vector3f.operator / did not return the expected value.");
        }

        // A test for operator + (Vector3f, Vector3f)
        [Fact]
        public void Vector3AdditionTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(4.0f, 5.0f, 6.0f);

            Vector3 expected = new Vector3(5.0f, 7.0f, 9.0f);
            Vector3 actual;

            actual = a + b;

            Assert.True(MathHelper.Equal(expected, actual), "Vector3f.operator + did not return the expected value.");
        }

        // A test for Vector3f (float, float, float)
        [Fact]
        public void Vector3ConstructorTest()
        {
            float x = 1.0f;
            float y = 2.0f;
            float z = 3.0f;

            Vector3 target = new Vector3(x, y, z);
            Assert.True(MathHelper.Equal(target.X, x) && MathHelper.Equal(target.Y, y) && MathHelper.Equal(target.Z, z), "Vector3f.constructor (x,y,z) did not return the expected value.");
        }

        // A test for Vector3f (Vector2f, float)
        [Fact]
        public void Vector3ConstructorTest1()
        {
            Vector2 a = new Vector2(1.0f, 2.0f);

            float z = 3.0f;

            Vector3 target = new Vector3(a, z);
            Assert.True(MathHelper.Equal(target.X, a.X) && MathHelper.Equal(target.Y, a.Y) && MathHelper.Equal(target.Z, z), "Vector3f.constructor (Vector2f,z) did not return the expected value.");
        }

        // A test for Vector3f ()
        // Constructor with no parameter
        [Fact]
        public void Vector3ConstructorTest3()
        {
            Vector3 a = new Vector3();

            Assert.Equal(a.X, 0.0f);
            Assert.Equal(a.Y, 0.0f);
            Assert.Equal(a.Z, 0.0f);
        }

        // A test for Vector2f (float, float)
        // Constructor with special floating values
        [Fact]
        public void Vector3ConstructorTest4()
        {
            Vector3 target = new Vector3(float.NaN, float.MaxValue, float.PositiveInfinity);

            Assert.True(float.IsNaN(target.X), "Vector3f.constructor (Vector3f) did not return the expected value.");
            Assert.True(float.Equals(float.MaxValue, target.Y), "Vector3f.constructor (Vector3f) did not return the expected value.");
            Assert.True(float.IsPositiveInfinity(target.Z), "Vector3f.constructor (Vector3f) did not return the expected value.");
        }

        // A test for Add (Vector3f, Vector3f)
        [Fact]
        public void Vector3AddTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(5.0f, 6.0f, 7.0f);

            Vector3 expected = new Vector3(6.0f, 8.0f, 10.0f);
            Vector3 actual;

            actual = Vector3.Add(a, b);
            Assert.Equal(expected, actual);
        }

        // A test for Divide (Vector3f, float)
        [Fact]
        public void Vector3DivideTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            float div = 2.0f;
            Vector3 expected = new Vector3(0.5f, 1.0f, 1.5f);
            Vector3 actual;
            actual = Vector3.Divide(a, div);
            Assert.Equal(expected, actual);
        }

        // A test for Divide (Vector3f, Vector3f)
        [Fact]
        public void Vector3DivideTest1()
        {
            Vector3 a = new Vector3(1.0f, 6.0f, 7.0f);
            Vector3 b = new Vector3(5.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(1.0f / 5.0f, 6.0f / 2.0f, 7.0f / 3.0f);
            Vector3 actual;

            actual = Vector3.Divide(a, b);
            Assert.Equal(expected, actual);
        }

        // A test for Equals (object)
        [Fact]
        public void Vector3EqualsTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(1.0f, 2.0f, 3.0f);

            // case 1: compare between same values
            object obj = b;

            bool expected = true;
            bool actual = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X = 10.0f;
            obj = b;
            expected = false;
            actual = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare between different types.
            obj = new Quaternion();
            expected = false;
            actual = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare against null.
            obj = null;
            expected = false;
            actual = a.Equals(obj);
            Assert.Equal(expected, actual);
        }

        // A test for Multiply (Vector3f, float)
        [Fact]
        public void Vector3MultiplyTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            const float factor = 2.0f;
            Vector3 expected = new Vector3(2.0f, 4.0f, 6.0f);
            Vector3 actual = Vector3.Multiply(a, factor);
            Assert.Equal(expected, actual);
        }

        // A test for Multiply (float, Vector3f)
        [Fact]
        public static void Vector3MultiplyTest2()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            const float factor = 2.0f;
            Vector3 expected = new Vector3(2.0f, 4.0f, 6.0f);
            Vector3 actual = Vector3.Multiply(factor, a);
            Assert.Equal(expected, actual);
        }

        // A test for Multiply (Vector3f, Vector3f)
        [Fact]
        public void Vector3MultiplyTest3()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(5.0f, 6.0f, 7.0f);

            Vector3 expected = new Vector3(5.0f, 12.0f, 21.0f);
            Vector3 actual;

            actual = Vector3.Multiply(a, b);
            Assert.Equal(expected, actual);
        }

        // A test for Negate (Vector3f)
        [Fact]
        public void Vector3NegateTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(-1.0f, -2.0f, -3.0f);
            Vector3 actual;

            actual = Vector3.Negate(a);
            Assert.Equal(expected, actual);
        }

        // A test for operator != (Vector3f, Vector3f)
        [Fact]
        public void Vector3InequalityTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(1.0f, 2.0f, 3.0f);

            // case 1: compare between same values
            bool expected = false;
            bool actual = a != b;
            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X = 10.0f;
            expected = true;
            actual = a != b;
            Assert.Equal(expected, actual);
        }

        // A test for operator == (Vector3f, Vector3f)
        [Fact]
        public void Vector3EqualityTest()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(1.0f, 2.0f, 3.0f);

            // case 1: compare between same values
            bool expected = true;
            bool actual = a == b;
            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X = 10.0f;
            expected = false;
            actual = a == b;
            Assert.Equal(expected, actual);
        }

        // A test for Subtract (Vector3f, Vector3f)
        [Fact]
        public void Vector3SubtractTest()
        {
            Vector3 a = new Vector3(1.0f, 6.0f, 3.0f);
            Vector3 b = new Vector3(5.0f, 2.0f, 3.0f);

            Vector3 expected = new Vector3(-4.0f, 4.0f, 0.0f);
            Vector3 actual;

            actual = Vector3.Subtract(a, b);
            Assert.Equal(expected, actual);
        }

        // A test for One
        [Fact]
        public void Vector3OneTest()
        {
            Vector3 val = new Vector3(1.0f, 1.0f, 1.0f);
            Assert.Equal(val, Vector3.One);
        }

        // A test for UnitX
        [Fact]
        public void Vector3UnitXTest()
        {
            Vector3 val = new Vector3(1.0f, 0.0f, 0.0f);
            Assert.Equal(val, Vector3.UnitX);
        }

        // A test for UnitY
        [Fact]
        public void Vector3UnitYTest()
        {
            Vector3 val = new Vector3(0.0f, 1.0f, 0.0f);
            Assert.Equal(val, Vector3.UnitY);
        }

        // A test for UnitZ
        [Fact]
        public void Vector3UnitZTest()
        {
            Vector3 val = new Vector3(0.0f, 0.0f, 1.0f);
            Assert.Equal(val, Vector3.UnitZ);
        }

        // A test for Zero
        [Fact]
        public void Vector3ZeroTest()
        {
            Vector3 val = new Vector3(0.0f, 0.0f, 0.0f);
            Assert.Equal(val, Vector3.Zero);
        }

        // A test for Equals (Vector3f)
        [Fact]
        public void Vector3EqualsTest1()
        {
            Vector3 a = new Vector3(1.0f, 2.0f, 3.0f);
            Vector3 b = new Vector3(1.0f, 2.0f, 3.0f);

            // case 1: compare between same values
            bool expected = true;
            bool actual = a.Equals(b);
            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X = 10.0f;
            expected = false;
            actual = a.Equals(b);
            Assert.Equal(expected, actual);
        }

        // A test for Vector3f (float)
        [Fact]
        public void Vector3ConstructorTest5()
        {
            float value = 1.0f;
            Vector3 target = new Vector3(value);

            Vector3 expected = new Vector3(value, value, value);
            Assert.Equal(expected, target);

            value = 2.0f;
            target = new Vector3(value);
            expected = new Vector3(value, value, value);
            Assert.Equal(expected, target);
        }

        // A test for Vector3f comparison involving NaN values
        [Fact]
        public void Vector3EqualsNanTest()
        {
            Vector3 a = new Vector3(float.NaN, 0, 0);
            Vector3 b = new Vector3(0, float.NaN, 0);
            Vector3 c = new Vector3(0, 0, float.NaN);

            Assert.False(a == Vector3.Zero);
            Assert.False(b == Vector3.Zero);
            Assert.False(c == Vector3.Zero);

            Assert.True(a != Vector3.Zero);
            Assert.True(b != Vector3.Zero);
            Assert.True(c != Vector3.Zero);

            Assert.False(a.Equals(Vector3.Zero));
            Assert.False(b.Equals(Vector3.Zero));
            Assert.False(c.Equals(Vector3.Zero));

            // Counterintuitive result - IEEE rules for NaN comparison are weird!
            Assert.False(a.Equals(a));
            Assert.False(b.Equals(b));
            Assert.False(c.Equals(c));
        }

        [Fact]
        public void Vector3AbsTest()
        {
            Vector3 v1 = new Vector3(-2.5f, 2.0f, 0.5f);
            Vector3 v3 = Vector3.Abs(new Vector3(0.0f, Single.NegativeInfinity, Single.NaN));
            Vector3 v = Vector3.Abs(v1);
            Assert.Equal(2.5f, v.X);
            Assert.Equal(2.0f, v.Y);
            Assert.Equal(0.5f, v.Z);
            Assert.Equal(0.0f, v3.X);
            Assert.Equal(Single.PositiveInfinity, v3.Y);
            Assert.Equal(Single.NaN, v3.Z);
        }

        [Fact]
        public void Vector3SqrtTest()
        {
            Vector3 a = new Vector3(-2.5f, 2.0f, 0.5f);
            Vector3 b = new Vector3(5.5f, 4.5f, 16.5f);
            Assert.Equal(2, (int)Vector3.SquareRoot(b).X);
            Assert.Equal(2, (int)Vector3.SquareRoot(b).Y);
            Assert.Equal(4, (int)Vector3.SquareRoot(b).Z);
            Assert.Equal(Single.NaN, Vector3.SquareRoot(a).X);
        }

        // A test to make sure these types are blittable directly into GPU buffer memory layouts
        [Fact]
        public unsafe void Vector3SizeofTest()
        {
            Assert.Equal(12, sizeof(Vector3));
            Assert.Equal(24, sizeof(Vector3_2x));
            Assert.Equal(16, sizeof(Vector3PlusFloat));
            Assert.Equal(32, sizeof(Vector3PlusFloat_2x));
        }

        [StructLayout(LayoutKind.Sequential)]
        struct Vector3_2x
        {
            private Vector3 _a;
            private Vector3 _b;
        }

        [StructLayout(LayoutKind.Sequential)]
        struct Vector3PlusFloat
        {
            private Vector3 _v;
            private float _f;
        }

        [StructLayout(LayoutKind.Sequential)]
        struct Vector3PlusFloat_2x
        {
            private Vector3PlusFloat _a;
            private Vector3PlusFloat _b;
        }

        [Fact]
        public void SetFieldsTest()
        {
            Vector3 v3 = new Vector3(4f, 5f, 6f);
            v3.X = 1.0f;
            v3.Y = 2.0f;
            v3.Z = 3.0f;
            Assert.Equal(1.0f, v3.X);
            Assert.Equal(2.0f, v3.Y);
            Assert.Equal(3.0f, v3.Z);
            Vector3 v4 = v3;
            v4.Y = 0.5f;
            v4.Z = 2.2f;
            Assert.Equal(1.0f, v4.X);
            Assert.Equal(0.5f, v4.Y);
            Assert.Equal(2.2f, v4.Z);
            Assert.Equal(2.0f, v3.Y);

            Vector3 before = new Vector3(1f, 2f, 3f);
            Vector3 after = before;
            after.X = 500.0f;
            Assert.NotEqual(before, after);
        }

        [Fact]
        public void EmbeddedVectorSetFields()
        {
            EmbeddedVectorObject evo = new EmbeddedVectorObject();
            evo.FieldVector.X = 5.0f;
            evo.FieldVector.Y = 5.0f;
            evo.FieldVector.Z = 5.0f;
            Assert.Equal(5.0f, evo.FieldVector.X);
            Assert.Equal(5.0f, evo.FieldVector.Y);
            Assert.Equal(5.0f, evo.FieldVector.Z);
        }

        private class EmbeddedVectorObject
        {
            public Vector3 FieldVector;
        }
    }
}


text:
"""
This module contains the forms used by the aswiki views.
"""

# Django imports
#
from django import forms
from django.utils.translation import ugettext_lazy as _

from aswiki.models import ImageAttachment, FileAttachment

####################################################################
#
class TopicForm(forms.Form):
    """
    To post an update to a topic pretty much just requires the new
    content for the topic.

    XXX This should check to make sure that the wiki markup being used
        is valid.
    """
    content = forms.CharField(label = _('Content'), required = True,
                              widget = \
                                  forms.Textarea(attrs = { 'cols': 95,
                                                       'rows': 30,
                                                       'class' : 'monospaced'}))
    reason = forms.CharField(label = _('Reason'), required = False,
                             widget = forms.TextInput(attrs = { 'size': '80'}),
                             max_length = 250)

####################################################################
#
class EditTopicForm(forms.Form):
    """
    To post an update to a topic pretty much just requires the new
    content for the topic.

    XXX This should check to make sure that the wiki markup being used
        is valid.
    """
    content = forms.CharField(label = _('Content'), required = True,
                              widget = \
                                  forms.Textarea(attrs = { 'cols': 95,
                                                       'rows': 30,
                                                       'class' : 'monospaced'}))
    reason = forms.CharField(label = _('Reason'), required = False,
                             widget = forms.TextInput(attrs = { 'size': '80'}),
                             max_length = 250)
    trivial = forms.BooleanField(label = _('Trivial change'), required = False,
                                 help_text = _("When checked this change will "
                                               "not cause a notice to be sent "
                                               "to the users watching this "
                                               "topic"))

####################################################################
#
class RenameTopicForm(forms.Form):
    """
    To rename a topic pretty much just requires the new name.
    """
    new_name = forms.CharField(label = _('New Name'), max_length = 128,
                               required = True)
    reason = forms.CharField(label = _('Reason'), required = False,
                             widget = forms.TextInput(attrs = { 'size': '80'}),
                             max_length = 250)

####################################################################
#
class DeleteTopicForm(forms.Form):
    """
    To delete an object you need to submit a form via POST that validates.
    """
    reason = forms.CharField(label = _('Reason'), required = False,
                             widget = forms.TextInput(attrs = { 'size': '80'}),
                             max_length = 250)

####################################################################
#
class AttachmentUploadForm(forms.ModelForm):
    class Meta:
        model = FileAttachment

####################################################################
#
class ImageUploadForm(forms.ModelForm):
    class Meta:
        model = ImageAttachment

####################################################################
#
class RevertTopicForm(forms.Form):
    """
    To revert a topic you need to submit a form via POST that validates.
    """
    reason = forms.CharField(label = _('Reason'), required = False,
                             widget = forms.TextInput(attrs = { 'size': '80'}),
                             max_length = 250)
    trivial = forms.BooleanField(label = _('Trivial change'), required = False,
                                 help_text = _("When checked this change will "
                                               "not cause a notice to be sent "
                                               "to the users watching this "
                                               "topic"))

####################################################################
#
def add_override_field(form):
    """
    When a topic is write locked we require that some forms submitted
    for altering that topic have an additional field 'override.'
    Override must be set in order for us to allow an action to proceed
    on a topic that is write locked (and that we do own the write lock
    on.)

    This will augment the given form with the boolean required
    override field.

    Arguments:
    - `form`: The instance of the form class we are going to add the
              `override` field to.
    """
    form.fields['override'] = \
        forms.BooleanField(label = _("Override write lock"),
                           help_text = _("This topic is locked for "
                                         "editing by another user. You "
                                         "must select this if you want "
                                         "to override their lock and "
                                         "commit your changes anyways."))
    return


text:
'use strict';

/**
 * Express.js methods that are either added to or replace methods of the Express response object.
 * @module Response
 */

module.exports = {

    /**
     * Replace express's ```send``` method with our own, so that we can output a log message, but
     * then call the parent (```res```) object's ```send``` to finish the job. Will trap calls to
     * ```res.json()``` and prevent those from recalling ```res.send()```.
     *
     * Attaches a private property ```_origSendCalled``` to the ```Response``` object. Also expects
     * the Response object's original ```send``` method to have been renamed to ```_origSend```.
     *
     * @param body Response body.
     * @returns this
     */
    send: function (body) {
        var res = this;
        var req = this.log.ctx.req;
        var log = this.log;

        log.data({ status: this.statusCode }).hrElapsed('responseTime');
        if (res._delayTime) {
            log.data('delay', res._delayTime);
        }
        // If you want to log more properties you can add them to res._logSendData
        if( res._logSendData ) {
            Object.keys(res._logSendData).forEach(function(key) {
                log.data(key,res._logSendData[key]);
            });
        }

        if (!res._origSendCalled) {
            log.action('response.send')._info();
        }
        // Trap case where res.json is called, which will result in res.send being called again
        if (typeof body === 'object' && body !== null && !Buffer.isBuffer(body)) {
            // settings
            var app = req.app;
            var replacer = app && app.get('json replacer') || null;
            var spaces = app && app.get('json spaces') || '  ';
            var s = JSON.stringify(body, replacer, spaces);

            // content-type
            if (!res.get('Content-Type')) {
                res.set('Content-Type', 'application/json');
            }
            res._origSendCalled = true;
            return res._origSend(s);
        } else {
            res._origSendCalled = true;
            return res._origSend.apply(this, arguments);
        }
    },

    /**
     * Replace express's ```end``` method with our own, so that we can output a log message, but
     * then call the parent (```res```) object's ```end``` to finish the job. Will not output a log
     * message if this was called from ```res.send()```.
     *
     * Expects
     * the Response object's original ```end``` method to have been renamed to ```_origEnd```.
     *
     * @returns this
     */
    end: function (body) {
        var res = this;
        if (!res._origSendCalled) {
            this.log.data({ status: this.statusCode }).hrElapsed('responseTime');
            if (res._delayTime) {
                this.log.data('delay', res._delayTime);
            }
            this.log.action('response.end')._info();
        }
        return this._origEnd.apply(this, arguments);
    },

    /**
     * Delay time is a field you can set manually to indicate a process has been 'paused' for whatever
     * reason, perhaps to back off on processing too many requests at the same time, or to
     * randomize password verification response time (the later being for security reasons). This value
     * can be inserted in log messages.
     *
     * @example
     *  log.data({delay:res.delayTime()}).info("Response delayed for password verification randomization")
     *
     * @returns {number} Delay time in milliseconds
     */
    delayTime: function () {
        return this._delayTime;
    }
};


text:
package erepnikov.servlets;

import erepnikov.dao.MusicTypeDAO;
import erepnikov.dao.UserDAO;
import erepnikov.models.User;
import erepnikov.repositories.Repository;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Class
 *
 * @author Egor Repnikov
 * @version 1.0.0
 * @since 19.09.2017
 */
public class AddMusicToUserServlet extends HttpServlet {

    /**
     * Repository for adding music type to user
     */
    private Repository repository;

    /**
     * Manager for getting users
     */
    private UserDAO userDAO;

    /**
     * Manger for getting music types
     */
    private MusicTypeDAO musicTypeDAO;

    @Override
    public void init() throws ServletException {
        this.repository = new Repository();
        this.userDAO = new UserDAO();
        this.musicTypeDAO = new MusicTypeDAO();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setAttribute("music_types", this.musicTypeDAO.getAll());
        HttpSession session = req.getSession();
        synchronized (session) {
            User user = (User) session.getAttribute("user");
            String userRole = user.getRole().getName();
            if (userRole.equals("admin") || userRole.equals("moderator")) {
                List<User> users = this.userDAO.getAll();
                for (User u : users) {
                    u.setMusicTypes(this.repository.getAllMusicTypesOfUser(u));
                }
                req.setAttribute("users", users);
            } else {
                List<User> users = new ArrayList<>();
                user.setMusicTypes(this.repository.getAllMusicTypesOfUser(user));
                users.add(user);
                req.setAttribute("users", users);
            }
        }
        req.getRequestDispatcher("WEB-INF/views/add_music_to_user.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.repository.addMusicTypeToUser(
                Integer.valueOf(req.getParameter("user_id")),
                Integer.valueOf(req.getParameter("music_type_id"))
        );
        resp.sendRedirect(String.format("%s/", req.getContextPath()));
    }
}


text:
require 'spec_helper'

describe ProfilesController do

  let(:user)  { FactoryGirl.create(:user) }

  before do
    login_user user
  end

  describe '#edit' do

    specify do
      get :edit
      assigns[:profile].should == user
      assigns[:title].should == 'Edit profile'
    end

  end

  describe '#update' do

    let(:user_attributes) { {'foo' => 'bar'} }

    context 'when successful' do
      specify do
        user.should_receive(:update_attributes).with(user_attributes) { true }
        put :update, :user => user_attributes
        assigns[:profile].should == user
        response.should redirect_to(root_url)
      end
    end

    context 'when unsuccessful' do
      specify do
        user.should_receive(:update_attributes).with(user_attributes) { false }
        put :update, :user => user_attributes
        assigns[:profile].should == user
        response.should render_template('edit')
      end
    end

  end

end


text:
package example.service;

import example.repo.Customer1333Repository;

import org.springframework.stereotype.Service;

@Service
public class Customer1333Service {
	public Customer1333Service(Customer1333Repository repo) {}
}